我正在使用带有 chrome 79 和 chromedriver 79 的 selenium 3.141.59。随机我RemoteWebDriver.get(url);
从 selenium 服务器中删除了一个异常。但是 Chrome 窗口保持打开状态。因此,我无法使用相同的用户目录创建新会话。在我每次尝试创建新会话时,chrome 窗口都会打开,但会话创建失败。所以那些所有打开的 Chrome 窗口都会导致内存泄漏!我试图从服务器设置超时和浏览器超时,但它没有帮助。知道发生了什么吗?
我正在通过以下方式启动服务器:
java -jar -Dselenium.LOGGER.level=ALL selenium-server-standalone-3.141.59.jar -timeout 250 -browserTimeout 300
我随机得到的例外:
Caused by: org.openqa.selenium.WebDriverException: java.net.ConnectException: Connection refused (Connection refused)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'myhost', ip: 'myip', os.name: 'Linux', os.arch: 'amd64', os.version: '4.14.154-128.181.amzn2.x86_64', java.version: '1.8.0_201'
Driver info: mypackage.SeleniumHelper$2
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 79.0.3945.88, chrome: {chromedriverVersion: 79.0.3945.36 (3582db32b3389..., userDataDir: /var/tmp/username...}, goog:chromeOptions: {debuggerAddress: localhost:35341}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webdriver.remote.sessionid: 66ddc30a30affc4ba52a539bc41...}
Session ID: 66ddc30a30affc4ba52a539bc411ac2c
at sun.reflect.GeneratedConstructorAccessor1082.newInstance(Unknown Source) ~[?:?]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_201]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_201]
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187) ~[selenium-remote-driver-3.141.59.jar:?]
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122) ~[selenium-remote-driver-3.141.59.jar:?]
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49) ~[selenium-remote-driver-3.141.59.jar:?]
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158) ~[selenium-remote-driver-3.141.59.jar:?]
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552) ~[selenium-remote-driver-3.141.59.jar:?]
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:277) ~[selenium-remote-driver-3.141.59.jar:?]
... 65 more
我的镀铬选项:
ChromeOptions options = new ChromeOptions ();
options.addArguments ("user-data-dir=/var/tmp/username");
options.addArguments ("disable-gpu");
options.addArguments ("disable-impl-side-painting");
options.addArguments ("disable-dev-shm-usage");
options.addArguments ("disable-infobars");
options.addArguments ("disable-gpu-sandbox");
options.addArguments ("no-sandbox");
options.addArguments ("disable-accelerated-2d-canvas");
options.addArguments ("disable-accelerated-jpeg-decoding");
options.addArguments ("test-type=ui");
options.addArguments ("no-proxy-server");