gpt4 book ai didi

java - Selenium Chrome 驱动程序 v92 : No connection (in v91 everything works fine)

转载 作者:行者123 更新时间:2023-12-04 14:06:03 25 4
gpt4 key购买 nike

我更新到 Chrome v92(下载了新的 chromedriver 92.0.4515.43,chrome 浏览器自动更新到 v92)

但现在我们的测试在由 jenkins 启动时不再有效。当我手动启动测试时,一切都在 headless 模式下工作。

通过jenkins出现如下错误:

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created
from disconnected: Unable to receive message from renderer
  (Session info: headless chrome=92.0.4515.107)
Build info: version: '4.0.0-beta-3', revision: '5d108f9a67'
System info: host: 'xxx' ip: 'xxxx', os.name: 'Windows Server 2016', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_202'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {desiredCapabilities=Capabilities {acceptSslCerts: true, browserName: chrome, goog:chromeOptions: {args: [--disable-notifications, --disable-popup-blocking, --headless, --disable-gpu], extensions: [], prefs: {download.default_directory: C:\xxxx\, profile.default_content_settings.popups: 0}}, pageLoadStrategy: normal}}]
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:84)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:62)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:153)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:128)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:619)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:251)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:173)
    at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:89)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:99)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:86)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:75)

这是代码,chrome已经初始化

System.setProperty("webdriver.chrome.driver", FilePath + "\\drivers\\chromedriver.exe");
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", FilePath);
ChromeOptions options = new ChromeOptions();
HashMap<String, Object> chromeOptionsMap = new HashMap<String, Object>();
options.setExperimentalOption("prefs", chromePrefs);
options.addArguments("--disable-notifications");
options.addArguments("--disable-popup-blocking");
options.addArguments("--headless");
options.addArguments("--disable-gpu");
options.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap);
options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
options.setCapability(ChromeOptions.CAPABILITY, options);
options.setPageLoadStrategy(PageLoadStrategy.NORMAL);
driver = new ChromeDriver(options);

使用 chromedriver v91 安装 Chrome v91 时一切正常。所以问题与 v92 的更新有关。

有人有想法吗?

有时会出现这个错误:

org.openqa.selenium.remote.http.ConnectionFailedException: Unable to establish websocket connection to http://localhost:60650/devtools/browser/9faa33dd-c789-47f4-acab-261acc7045e7
Build info: version: '4.0.0-beta-3', revision: '5d108f9a67'
System info: host: 'xxx', ip: 'xxx', os.name: 'Windows Server 2016', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_202'
Driver info: driver.version: ChromeDriver
    at org.openqa.selenium.remote.http.netty.NettyWebSocket.<init>(NettyWebSocket.java:104)
    at org.openqa.selenium.remote.http.netty.NettyWebSocket.lambda$create$3(NettyWebSocket.java:136)
    at org.openqa.selenium.remote.http.netty.NettyClient.openSocket(NettyClient.java:111)
    at org.openqa.selenium.devtools.Connection.<init>(Connection.java:73)
    at org.openqa.selenium.chromium.ChromiumDriver.lambda$new$1(ChromiumDriver.java:102)
    at java.util.Optional.map(Unknown Source)
    at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:100)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:99)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:86)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:75)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    org.openqa.selenium.remote.http.ConnectionFailedException: Unable to establish websocket connection to http://localhost:60650/devtools/browser/9faa33dd-c789-47f4-acab-261acc7045e7
Build info: version: '4.0.0-beta-3', revision: '5d108f9a67'
System info: host: 'xxx', ip: 'xxx', os.name: 'Windows Server 2016', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_202'
Driver info: driver.version: ChromeDriver
    at org.openqa.selenium.remote.http.netty.NettyWebSocket.<init>(NettyWebSocket.java:104)
    at org.openqa.selenium.remote.http.netty.NettyWebSocket.lambda$create$3(NettyWebSocket.java:136)
    at org.openqa.selenium.remote.http.netty.NettyClient.openSocket(NettyClient.java:111)
    at org.openqa.selenium.devtools.Connection.<init>(Connection.java:73)
    at org.openqa.selenium.chromium.ChromiumDriver.lambda$new$1(ChromiumDriver.java:102)
    at java.util.Optional.map(Unknown Source)
    at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:100)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:99)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:86)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:75)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)

最佳答案

尝试执行您的代码:

options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");

/dev/shm 分区在某些 VM 环境中太小,导致 Chrome 失败或崩溃(参见 http://crbug.com/715363 )。使用此标志解决此问题(临时目录将始终用于创建匿名共享内存文件)。

引用:

https://peter.sh/experiments/chromium-command-line-switches/

关于java - Selenium Chrome 驱动程序 v92 : No connection (in v91 everything works fine),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68470140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com