Could anybody throw me some idea on my query?
Query: In my application, there is a pop up which comes frequently, but some times it does not come. I have to check whether the pop up is there or not, and then perform action on that. This pop up also takes some time to be appeared in the page.
My Solution: First I waited for the pop up by explicit wait condition. Then by a if loop i m checking whether the pop up is displayed on the page or not. if displayed then do actions, else do other action.
Now, if the pop up does not come, i m getting time out exception.
Here is my code:
FluentWait<WebDriver> wait_1 = new FluentWait<WebDriver>(driver)
.withTimeout(30, TimeUnit.SECONDS)
.pollingEvery(5, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class)
.ignoring(TimeoutException.class);
//getting time out exception if pop up does not exists
wait_1.until(ExpectedConditions.visibilityOfElementLocated(By.id("some id")));
if(driver.findElement(By.id("some id")).isDisplayed()) {
System.out.println(driver.findElement(By.id("some id")).getText());
//click some elements
}
else{
// `enter code here`
}