简体   繁体   中英

hide the webpage in selenium webdriver while testing

While running the test in selenium Webdriver using JAVA, I do not want the webpage to be seen on the screen. Is there a way that the program runs and the webpage is not seen.

If you don't have the budget for a dedicated machine to run tests, then a simple trick is to launch the browser off-screen:

ChromeOptions options = new ChromeOptions();
options.addArguments("--window-position=-32000,-32000");

WebDriver driver = new ChromeDriver(options);
driver.get("http://stackoverflow.com");

Yes you can do this like below Use HtmlUnitDriver it opens your web page in headless mode ie no visibility of any web page for more info about html unit driver please visit

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

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

Now back to question

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM