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 ?
Asked
Active
Viewed 1,110 times
0
-
while doing something else ? elaborate more. – cruisepandey May 15 '18 at 08:29
-
1How about using a headless webdriver? This way your tests will run in background, without any UI – Hlib Barylskyi May 15 '18 at 08:34
-
Possible duplicate of [How to run chrome driver in background using selenium with Ruby for Mac OSx?](https://stackoverflow.com/questions/43863837/how-to-run-chrome-driver-in-background-using-selenium-with-ruby-for-mac-osx) – undetected Selenium May 15 '18 at 09:24
1 Answers
0
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());
}
-
My cases requires manual support in some part that's why I wanted to avoid headless browser. I wanted to run them in background and maximize window when manual part is needed but I didn't expected that it will lose focus. – kris82pl May 16 '18 at 10:06
-
Can give me your code? so I can understand it and give you solution – Jaydeep Gohel May 22 '18 at 06:34