如何在IE中运行selenium不显示浏览器窗口?

时间:2016-08-29 08:22:19

标签: selenium selenium-webdriver selenium-iedriver

操作系统是windows10,编程语言是JAVA,浏览器是IE11。如何在没有浏览器窗口的情况下运行硒?

2 个答案:

答案 0 :(得分:1)

您可以使用phantonjs,HtmlUnitDriver或无头镀铬

对于HtmlUnitDriver

WebDriver driver=new HtmlUnitDriver();
driver.get("http://google.com"); 

对于phantomjs首先下载ghostdriver并使用

System.setProperty("phantomjs.binary.path", "E:\\phantomjs-2.1.1-windows\\phantomjs.exe");  
WebDriver driver = new PhantomJSDriver();   
driver.get("http://google.com");  

对于Chrome下载Chromedriver并使用

System.setProperty("webdriver.chrome.driver","E:/software and tools/chromedriver_win32/chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("headless");
driver.get("http://google.com"); 

答案 1 :(得分:0)

使用像phantomjs这样的无头浏览器,使用selenium webdriver运行htmlunit。