? Article source:
Pinterest: Http://www.jianshu.com/p/b01de206a0d7
In the past we executed selenium scripts, and if we were to improve the execution speed of our scripts, we might consider using htmlunit or more headless browsers that use PHANTOMJS, but these tools are not good for JavaScript support. For the support of the web is not good, occupy more resources, and real browser there are some differences and so on.
Now, the Chrome browser offers headless chrome, which simply says we can execute our selenium script under chrome without opening the chrome GUI.
If you want to use headless chrome for the chrome version, we can see from the official documentation that the MAC and Linux environments require that the chrome version is 59+, and that the Windows version of Chrome is 60+, At the same time Chromedriver requires 2.30+ version
Assuming your environment is already in place, then I run the following Java demo example directly to feel the following:
@Test public
void Openchrometest () {
String path = System.getproperty ("User.dir");
System.setproperty ("Webdriver.chrome.driver", Path + "\\drivers\\chromedriver.exe");
Chromeoptions chromeoptions = new Chromeoptions (); set to headless mode (must)
chromeoptions.addarguments ("--headless"); Set browser window open size (not required)
chromeoptions.addarguments ("--window-size=1920,1080");
Webdriver Driver = new Chromedriver (chromeoptions);
Driver.get ("http://www.baidu.com");
String title = Driver.gettitle ();
System.out.println (title);
Driver.quit ();
}
Script run we did not see any Chrome browser launch, but the console also output exactly:
If you want to learn more about headless chrome, you can view the official website document: Https://developers.google.cn/web/updates/2017/04/headless-chrome
Finally, from the official Firefox, Firefox will also launch headless mode, is expected in the Linux environment 55 release, and the Firefox 56 version on the full platform launch. Worth looking forward to.