How to Run Selenium Webdriver in the Background

Can Selenium WebDriver open browser windows silently in the background?

There are a few ways, but it isn't a simple "set a configuration value". Unless you invest in a headless browser, which doesn't suit everyone's requirements, it is a little bit of a hack:

How to hide Firefox window (Selenium WebDriver)?

and

Is it possible to hide the browser in Selenium RC?

You can 'supposedly', pass in some parameters into Chrome, specifically: --no-startup-window

Note that for some browsers, especially Internet Explorer, it will hurt your tests to not have it run in focus.

You can also hack about a bit with AutoIt, to hide the window once it's opened.

running webdriver selenium in background

No, you can not change actively running Selenium WebDriver session from normal to headless and vice versa.

In the similar manner you will not be able to re-define default downloading folder, no-sandbox, disable-dev-shm-usage etc.

All these parameters are loaded during the WebDriver object creating and can not be changed for existing, running WebDriver instance.

How to run selenium webdriver in the background?

Try PhantomJS which is a headless browser webkit. HTMLUnit is also similar to PhantomJs; however, usage of PhamtomJs is highly recommended.

PhantomJs uses Google chrome's JavaScript Engine but without a GUI.

Refer :http://phantomjs.org/

Selenium WebDriver running in background

For running Selenium WebDriver in background you need to use headless webdriver for that you can use following code

    public static void main(String[] args) {

// Declaring and initialising the HtmlUnitWebDriver
HtmlUnitDriver unitDriver = new HtmlUnitDriver();

// open google.com webpage
unitDriver.get("http://google.com");

System.out.println("Title of the page is -> " + unitDriver.getTitle());

// find the search edit box on the google page
WebElement searchBox = unitDriver.findElement(By.name("q"));

// type in Selenium
searchBox.sendKeys("Selenium");

// find the search button
WebElement button = unitDriver.findElement(By.name("gbqfba"));

// Click the button
button.click();

System.out.println("Title of the page is -> " + unitDriver.getTitle());

}


Related Topics



Leave a reply



Submit