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?