【发布时间】:2017-06-27 10:23:26
【问题描述】:
我在这里使用 maven。这是我的 Selenium 代码:
DesiredCapabilities capb = DesiredCapabilities.chrome();
capb.setCapability("chrome.binary","/Applications/Google Chrome.app/Contents/MacOS/Google Chrome");
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless","--disable-gpu", "--no-sandbox","--remote-debugging-port=9222");
capb.setCapability(ChromeOptions.CAPABILITY, options);
System.setProperty("webdriver.chrome.driver","/Users/nitinkumar/TEST/chromedriver");
try{
ChromeDriver driver = new ChromeDriver(capb);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("https://qa.cmnetwork.co");
driver.quit();
}
catch(Exception e)
{
e.printStackTrace();
}
当我运行“mvn test”时,它会以 GUI 模式启动 chrome。但它应该以无头模式打开。我有 chrome vesrion 59.0、OS X yosemite(10.10.5)、chromedriver 2.30 和 Selenium 3.4.0 .
【问题讨论】:
-
值得一提的是
Headless mode is available on Mac and Linux in Chrome 59. Windows support is coming in Chrome 60. To check what version of Chrome you have, open chrome://version. -
我已经在我的问题中提到过。我现在把它加粗了。
-
如何设置像
driver = new ChromeDriver(options);这样的选项 -
已尝试但仍以 GUI 模式而不是无头模式打开。
标签: selenium selenium-chromedriver google-chrome-headless