I have an issue with Selenium Firefox Driver where sometimes a google ad of some kind gets stuck loading. I can get by this by simply clicking the refresh button and the page will fully load, I can read the data I need and move onto the next page. If I don't manually click refresh it will eventually timeout with the default timeout time but this takes a few minutes.
This of course isn't ideal and I was hoping that I could handle this scenario automatically.
I tried manually changing the timeout time and adding a Try Catch block as can be seen below
FirefoxDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 30);
FixturesDataStore fixtures = new FixturesDataStore();
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
for(int i = 0; i < fixtures.getHomeTeams().size(); i++)
{
try
{
driver.navigate().to(FORMURL.concat( (fixtures.getHomeTeams().get(i)).replace( ' ', '+' )));
}catch(WebDriverException e)
{
System.out.println("What a catch!!");
driver.navigate().refresh();
}
The error is:
Exception in thread "main" org.openqa.selenium.TimeoutException: Timeout loading page after 10000ms
It highlights the line
driver.navigate().refresh();
as causing the error.
The result is pretty much as expected and as per the specifications.
This error message...
Exception in thread "main" org.openqa.selenium.TimeoutException: Timeout loading page after 10000ms
...is the result of pageLoadTimeout()
which you have configured as:
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
For a detailed analysis about the reason for the exception you can always catch the WebDriverException. You can find a detailed discussion in pageLoadTimeout in Selenium not working.
How to make selenium to reload the desired url if it takes too long loading