I have test case with following scenario:
1) Navigate to website.
2) Enter Login Credential.
3) Click on Login.
After login in my application I have hint popup for end user. I use window handler for closing it but problem is sometimes selenium runs so fast that it clicks on it before it is visible. Any help will be appreciated.
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(60, TimeUnit.SECONDS)
.pollingEvery(2, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);
String mainWindowHandle = driver.getWindowHandle();
driver.switchTo().parentFrame();
wait.until(ExpectedConditions.urlContains("client/default"));
wait.until(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver d) {
System.out.println(String.format("Window size is %d", d.getWindowHandles().size()));
return (d.getWindowHandles().size() == 1);
}
});
for (String activeHandle : driver.getWindowHandles()) {
if (!activeHandle.equals(mainWindowHandle)) {
driver.switchTo().window(activeHandle);
}
}
driver.findElement(By.xpath(elementLocator("popup_close_button"))).click();
driver.switchTo().window(mainWindowHandle); // switch back to parent window