I am facing an issue in automating a web application using selenium web driver.
The webpage has a button which when clicked opens a new window. When I use the follow
Below function can wait for given max time until your new window is open
public static void waitForWindow(int max_sec_toWait, int noOfExpectedWindow) {
FluentWait wait = new FluentWait(driver);
wait.pollingEvery(Duration.ofMillis(200));
wait.withTimeout(Duration.ofSeconds(max_sec_toWait));
wait.ignoring(NoSuchWindowException.class);
Function function = new Function(){
@Override
public Boolean apply(WebDriver driver) {
Set handel = driver.getWindowHandles();
if(handel.size() == noOfExpectedWindow)
return true;
else
return false;
}
};
wait.until(function);
}