selenium chrome 驱动程序v92:无连接(在v91中一切正常)

6xfqseft  于 2023-03-16  发布在  Go
关注(0)|答案(4)|浏览(217)

我更新到Chrome v92(新的chromedriver 92.0.4515.43已下载,Chrome浏览器自动更新到v92)
但是现在我们的测试在jenkins启动的时候不起作用了,当我手动启动测试的时候一切都在无头模式下工作。
通过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安装chromev91时,一切正常。所以问题与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)
9fkzdhlc

9fkzdhlc1#

尝试使用以下命令执行代码:

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/

wkftcu5l

wkftcu5l2#

添加这两行代码对我很有效:
选项。addArguments(“--无沙箱”);
选项。添加参数(“--禁用扩展”);

svgewumm

svgewumm3#

添加以下色度选项:

ChromeOptions co = new ChromeOptions();
co.addArguments("--remote-allow-origins=*");
WebDriver driver = new ChromeDriver(co);
driver.get("https://www.google.com");
wz1wpwve

wz1wpwve4#

ChromeOptions co = new ChromeOptions();    
co.addArguments("--remote-allow-origins=*");
driver = new ChromeDriver(co);

试着用这个,它对我很有效

相关问题