1

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.

  • Do you get some error messages when driver.findElement(popUpClose).click()? – Mate Mrše Apr 10 at 12:57
  • No, but I need to wait for some times before I click it. It is clickable, but I would like to wait before I click it. – plaidshirt Apr 11 at 5:53
1

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.