[英]Headless Chrome run with selenium
System.setProperty("webdriver.chrome.driver", "/usr/bin/google-chrome");
final ChromeOptions chromeOptions = new ChromeOptions();
//chromeOptions.addArguments("headless");
chromeOptions.addArguments("window-size=1200x600");
final DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
final URL url = new URL("https://the-internet.herokuapp.com/login");
final WebDriver driver = new RemoteWebDriver(url, desiredCapabilities);
失败为:
线程“主要” org.openqa.selenium.WebDriverException中的异常:无法解析远程响应:
未找到
知道为什么吗?
您的Chrome浏览器,chromedriver和Selenium有哪些版本? 我尝试了:
如下代码:
System.setProperty("webdriver.chrome.driver", "/pathTo/chromedriver);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
ChromeDriver driver = new ChromeDriver(chromeOptions);
driver.get("https://the-internet.herokuapp.com/login");
System.out.println(driver.getTitle());
注意:在当前版本的Selenium和ChromeDriver中,替换为:
chromeOptions.addArguments("--headless");
同
chromeOptions.setHeadless(true);
参考: https : //seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/chrome/ChromeOptions.html#setHeadless-boolean-还必须设置Window大小,否则它将在移动模式下呈现,并且可能无法在页面中获取某些元素。
chromeOptions.addArguments("--window-size=1200x600");
在带有硒3.14.0的chromedriver 2.42.591071上测试
输出:
The Internet
查看有关浏览器支持版本的Headless Chrome入门 。
options.addArguments("headless");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
这对我有用。 Chromedriver版本:2.37
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.