[JAVA] Chrome59 Comparison of normal and headless mode operation

It seems that Chrome 59 was released around 2017/06/05. I think that there are many people who have been looking forward to it because this version supports headless mode. However, the latest version of the driver ChromeDriver 2.29 only supports up to Chrome 58, so you have to wait for a while. However, it can be moved to some extent, so it is possible to be prepared.

How to operate in headless mode

Normally (non-headless mode), the combination of Chrome59 + ChromeDriver2.29 seems to work without problems.

System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");

WebDriver driver = new ChromeDriver();
driver.get("http://qiita.com/");

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("/path/to/screenshot.png "));

driver.quit();

Then, add Chrome parameters by referring to "Headless Chrome Beginning".

System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");

//Chrome parameter "--headless --disable-"gpu" designation
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless", "--disable-gpu");

// WebDriver driver = new ChromeDriver();
WebDriver driver = new ChromeDriver(options);
driver.get("http://qiita.com/");

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("/path/to/screenshot.png "));

driver.quit();

If you do this, you can take screenshots even in an environment without a display.

Comparison of current operation

Maybe it's just my Linux environment, but I can see some differences in behavior that I don't understand well. It seems better to use it with caution until it stabilizes.

Proxy settings do not work

If you use a proxy that is different from the OS settings, the parameters in Chrome

-–proxy-server="http=xxx.xxx.xxx.xxx:8080;https=xxx.xxx.xxx.xxx:8080"
--proxy-bypass-list="local-test-server"

It should be specified as, but if you add this in headless mode

python


WebDriver driver = new ChromeDriver(options);

It will stop around.

Unable to access site with certificate issue

When I try to access a site that has a red triangle on the left side of the URL

python


driver.get(url);

It will stop at. There is no change even if I add the Chrome parameter --ignore-certificate-errors.

Window switching process does not work

For sites involving multiple windows

python


driver.switchTo().window(windowId);

I switch like this, but it doesn't switch even after waiting a few minutes.

Recommended Posts

Chrome59 Comparison of normal and headless mode operation
Comparison of Android Handler Looper and runOnUiThread
About the operation of next () and nextLine ()
Thorough comparison of Android and iOS implementations
[Java / Swift] Comparison of Java Interface and Swift Protocol
[Java] Collection and StringBuilder operation method comparison
Comparison of JavaScript objects and Ruby classes
Equivalence comparison of Java wrapper classes and primitive types