I'd like to have my selenium webdriver running in background while doing something else but each time I switch from window where test is executing it fails. It seems that WebDriver doesn't remember handler for window where started tests - is it ok behaviour ? What is solution then ?
0
votes
1 Answers
0
votes
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());
}