WebDriver to close popup window after certain time



  • I have a Selenium WebDriver based test, which fill a form and send it for processing. During time period of processing a window is opened. Sometimes processing fails, but this window is not closed, so we can't get result. Purpose of this test is to get the result. I try to set a timeout for this window, so it should be closed after a predefined time (I set it to 10 seconds now.) by WebDriver and form should be resent. I use following code.

    WebElement webElement;
    try {
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.findElement(sendButton).click();
        webElement = wait.until(ExpectedConditions.presenceOfElementLocated(By.className("button-resultdown")));
    } catch (TimeoutException ex) {
        webElement = null;
    } finally {
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    }
    if (webElement == null) {
        driver.findElement(popUpClose).click();
        TimeUnit.SECONDS.sleep(4);
        driver.findElement(sendButton).click();
    }
    

    Popup window is not closed automatically after 10 seconds. I checked element locators, those are valid.



  • Can you not make a note of the starting Window / Tab then just switch back to it?

    String firstTab = driver.getWindowHandle();
    
    //Do the click event
    
    driver.switchTo().window(firstTab);
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2