[英]unknown error: Chrome failed to start: crashed(selenium ,headless mode)
i have this code and one problem(description under code) in its execution 我有此代码和执行中的一个问题(代码下的描述)
try {
ChromeOptions options = new ChromeOptions();
options.setBinary("/usr/bin/chromium-browser");
options.addArguments("--start-maximized");
options.addArguments("headless");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setBrowserName("chrome");
capabilities.setPlatform(Platform.LINUX);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = null;
// here throws exception
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), capabilities);
}catch (Exception ex){
int point = 0;
}
I use: 我用:
and when i create RemoteWebDriver i get this error: Exception: unknown error: Chrome failed to start: crashed 当我创建RemoteWebDriver时,出现以下错误:异常: 未知错误:Chrome无法启动:崩溃
command to start selenium-server 启动硒服务器的命令
DISPLAY=:1 xvfb-run java -Dwebdriver.chrome.driver="/home/builds/chromedriver" -jar /home/builds/selenium-server-standalone-3.7.1.jar
which of the parts of this scheme can be the cause of the described error? 该方案的哪一部分可能是所描述错误的原因?
First all the argument you have entered is wrong for headless. 首先,您输入的所有论点都是无稽之谈。
It's --headless
not headless
这
--headless
不headless
Use below code 使用以下代码
options.addArguments("--headless");
Another thing you have to pass System.setProperty
like below: 另一件事,您必须像下面这样传递
System.setProperty
:
System.setProperty("webdriver.chrome.driver","E:\\Selenium\\src\\libs\\chromedriver.exe");
The code working fine from my side is: 就我而言,工作正常的代码是:
try {
System.setProperty("webdriver.chrome.driver","E:\\Selenium\\Workplace\\Selenium\\src\\libs\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
// options.setBinary("/usr/bin/chromium-browser");
options.addArguments("--start-maximized");
options.addArguments("--headless");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setBrowserName("chrome");
capabilities.setPlatform(Platform.WINDOWS);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
driver.get("http://google.com");
}catch (Exception ex){
int point = 0;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.