0

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 ?

kris82pl
  • 977
  • 3
  • 12
  • 21

1 Answers1

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