C# Webdriver - Page Title assert fails before page loads C# Webdriver - Page Title assert fails before page loads selenium selenium

C# Webdriver - Page Title assert fails before page loads


Implicit waits work only for finding elements. For waiting on the title of the page to be a certain value, you'll want to use an explicit wait. You can write your own version of this pattern, but in the .NET bindings, the WebDriver.Support.dll assembly has a WebDriverWait class to help with this. Its use would look something like this:

// WARNING! Untested code written from memory below. It has not// been tested or even compiled in an IDE, so may be syntactically// incorrect. The concept, however, should still be valid. public void WaitForTitle(IWebDriver driver, string title, TimeSpan timeout){    WebDriverWait wait = new WebDriverWait(driver, timeout);    wait.Until((d) => { return d.Title == title; });}

You could even modify your IsAt method to use this pattern, catching the WebDriverTimeoutException and returning false if the wait function times out.