I want selenium to force the browser to reload the page which it is loading if the loading process takes too long.
From StackOverflow I have that this code
new WebDriverWait(driver, 30).until((ExpectedCondition<Boolean>) wd -> ((JavascriptExecutor) wd)
.executeScript("return document.readyState").equals("complete"));
will wait until the page is fully loaded, but I want it to be reloaded if it takes more than 30 seconds.
How can I achieve that?
To reload the webpage incase the loading process is taking too long you can configure pageLoadTimeout.
pageLoadTimeoutsets the amount of time to wait for a page load to complete before throwing an error. If the timeout is negative, page loads can be indefinite.An example (using Selenium v3.141.59 and GeckoDriver v0.24.0):
Code Block:
Console Output:
You can find a relevant discussion in pageLoadTimeout in Selenium not working