在测试时将网页隐藏在selenium webdriver中



使用JAVA在selenium Webdriver中运行测试时,我不希望在屏幕上看到网页。有没有一种方法可以让程序运行而不看到网页。

如果你没有预算让专用机器运行测试,那么一个简单的技巧就是在屏幕外启动浏览器:

ChromeOptions options = new ChromeOptions();
options.addArguments("--window-position=-32000,-32000");
WebDriver driver = new ChromeDriver(options);
driver.get("http://stackoverflow.com");

是的,你可以像下面这样做。使用HtmlUnitDriver它以无头模式打开你的网页,即任何网页都不可见。有关html单元驱动程序的更多信息,请访问

https://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/htmlunit/HtmlUnitDriver.html

也是visit http://stackoverflow.com/questions/12807689/selenium-vs-htmlunit

现在回到问题

WebDriver driver = new HtmlUnitDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// do some action with html unit driver
// for example open google home page
driver.get("http://www.google.com");
// now verify that google home page is loaded properly
System.out.println("Printing Title of the Google Home Page : " + driver.getTitle());
// above line prints on console : Printing Title of the Google Home Page : Google

最新更新