我在centos上运行无头镀铬,无头镀铬版本2.38,以及google-chrome-stable版本67.0
System.setProperty("webdriver.chrome.driver", driverPath);
log.warn("chrome driver path is : {}", driverPath);
List<String> options = proxyConfig.getChromeOptions();
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments(options);
Map<String, String> capabilites = proxyConfig.getCapabilities();
if(MapUtils.isNotEmpty(capabilites)) {
for (Map.Entry<String, String> entry : capabilites.entrySet()) {
chromeOptions.setCapability(entry.getKey(), entry.getValue());
}
}
// proxy configuration
/*Proxy proxy = new Proxy();
proxy.setProxyType(Proxy.ProxyType.MANUAL);
proxy.setHttpProxy(proxyConfig.getProxyHost());
proxy.setSocksUsername(proxyConfig.getProxyUsername());
proxy.setSocksPassword(proxyConfig.getProxyPassword());
chromeOptions.setCapability(CapabilityType.PROXY, proxy);*/
log.warn("chorme driver created ");
return new ChromeDriver(chromeOptions);
chrome选项:
"--headless",
"----disable-gpu",
"--ignore-certificate-errors",
"window-size=1920,1080"
它在最后一行给出了以下给出的错误消息:
org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: crashed
(Driver info: chromedriver=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Linux 4.9.77blibli.com x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 60.11 seconds
Build info: version: ‘3.6.0’, revision: ‘6fbf3ec767’, time: ‘2017-09-27T15:28:36.4Z’
System info: host: ‘csrapp-02’, ip: ‘127.0.1.1’, os.name: ‘Linux’, os.arch: ‘amd64’, os.version: ‘4.9.77dwdwde.com’, java.version: ‘1.8.0_101’
Driver info: driver.version: ChromeDriver
我已经验证了chrome和chromedriver版本,它兼容。无法理解为什么它没有在centos上运行? 相同的代码在mac
上工作正常pom
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.12.0</version>
</dependency>
答案 0 :(得分:1)
此错误消息......
org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: crashed
...表示 ChromeDriver 无法启动/生成新的 WebBrowser ,即 Chrome浏览器会话。
当您在CentOS上使用 无头Chrome 时,值得一提的是,根据讨论Getting Started with Headless Chrome --disable-gpu
是Temporarily needed if running on Windows.
--disable-gpu \ # Temporarily needed if running on Windows.
但是,您的主要问题是您使用的二进制文件版本之间的不兼容,如下所示:
因此, JDK v8u101 , Selenium Client v3.6.0 , ChromeDriver v2.38 与之间存在明显的不匹配Chrome浏览器v67.0
@Test
。driver.quit()
方法中调用tearDown(){}
以关闭&amp;正常销毁 WebDriver 和 Web客户端实例。