0

I use the following function to wait for a page to be fully loaded before processing it:

protected bool WaitForPageLoad(){
    return new WebDriverWait(Driver, TimeSpan.FromSeconds(20)).Until(d => ((IJavaScriptExecutor)d).ExecuteScript("return document.readyState").Equals("complete"));
}

Sometimes IJavaScriptExecutor.ExecuteScript() return an OpenQA.Selenium.NoSuchWindowException and despite the fact that I enclose the WaitForPageLoad() call in a try catch block, that exception still isn't caught.

How do I catch it?

Jos B
  • 87
  • 3
  • 12

1 Answers1

0

You can configure your webdriverwait to ignore certain exceptions.

You can use it like this:

var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
wait.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(NoSuchWindowException));
wait.Until(d=> ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
RichEdwards
  • 3,423
  • 2
  • 6
  • 22