I'm having some problem handling timeouts as it doesn't seem to be working in every situation. I have defined the timeout as follows:
wait = new FluentWait<WebDriver>(driver)
.withTimeout(Duration.ofSeconds(60))
.pollingEvery(Duration.ofSeconds(1))
.ignoring(NoSuchElementException.class);
Now, when I want to wait until an element is present on the page, I use this piece of code :
wait.until(ExpectedConditions.presenceOfElementLocated(locator));
It works in most of the situation (wait for the element and timeout after 60 seconds) but lately we've been having trouble with some of the pages that get stuck loading (there's a message waiting for ... at the bottom left of the page). When this happens, I realize that this piece of code doesn't work properly. It doesn't timeout after 60 seconds but after 10 minutes.
Edit: Actually, trying to investigate my problem a little more, I realized it really comes from another line of code that also contains the wait:
wait.until(ExpectedConditions.elementToBeClickable(locator));
Basically, I click on a link that redirects to another page, wait for a button to be present, wait for the button to be clickable, and click on the button. So it detects the button is present but then it waits for it to be clickable and doesn't time out after 60 seconds.
So when I define my driver, I added the following line:
driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
In the console, I see the following line: Timed out receiving message from renderer: 60.000
But how do I catch this exception? I tried to surround my wait with a try/catch but it doesn't work.
try {
wait.until(ExpectedConditions.elementToBeClickable(locator));
} catch (Exception e) {
logger.info("TEST");
throw new TimeoutException("element " + locator.toString() + " not found on the page");
}
How can I do it? Thanks.