2017-10-09 731 views
0

运行我想运行在无头模式的脚本为所有3个浏览器的Chrome,火狐& IE如何设置能力IE浏览器在无头模式

以下是Chrome的代码:

System.setProperty("webdriver.chrome.driver", "./drive/chromedriver.exe"); 

    ChromeOptions options = new ChromeOptions(); 

    options.addArguments("headless"); 

    options.addArguments("window-size=1400,600"); 

    WebDriver driver = new ChromeDriver(options); 

    driver.get("http://www.google.com/"); 

注:它的做工精细

火狐:

FirefoxBinary firefoxBinary = new FirefoxBinary(); 

    firefoxBinary.addCommandLineOptions("--headless"); 

    System.setProperty("webdriver.gecko.driver", "./drive/geckodriver.exe"); 

    FirefoxOptions firefoxOptions = new FirefoxOptions(); 

    firefoxOptions.setBinary(firefoxBinary); 

    FirefoxDriver driver = new FirefoxDriver(firefoxOptions); 

    driver.get("http://www.google.com/"); 

注:它的做工精细

IE:

同样地,我想在IE的选项

执行

回答

0

IE没有一个无头模式的支持(因为IE现在不收到任何更新或改进)。

但是,您可以使用trifle.js,这是一种浏览器,可以在无头模式下模拟某些IE版本,因为它被编码为PhantomJS的一个端口。

相关问题