3 answers, which you can combine:
- Set implicit wait immediately after creating the web driver instance:
_ = driver.Manage().Timeouts().ImplicitWait;
This will try to wait until the page is fully loaded on every page navigation or page reload. - After page navigation, call JavaScript
return document.readyState
until"complete"
is returned. The web driver instance can serve as JavaScript executor. Sample code:C#new WebDriverWait(driver, MyDefaultTimeout).Until( d => ((IJavaScriptExecutor) d).ExecuteScript("return document.readyState").Equals("complete"));
Javanew WebDriverWait(firefoxDriver, pageLoadTimeout).until( webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));
- Check if the URL matches the pattern you expect.