2017-10-09 728 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的一個端口。

相關問題