Search Here!

Saturday, February 16, 2013

WebDriver Wait Till Page Successfully Switched To Another Page

Sometimes, Due to Build slowness we are not able to switch to another page successfully. The WebDriver throws exception either we are doing the correct thing. So, we need to wait for particular time to page get switched successfully and we needverify it through page title.

///
/// Waits for page switched to another page successfully.
///

/// The expected title, which must be an exact match.
/// This is the time to wait for HTML element to appear on the page.
/// If the element not able to find in the specified time.

/// True when the title matches, false otherwise throws the exception.

/// An expectation for checking the title of a page.

protected bool WaitForPageGetSwitched(string expectedPageTitle, int timeOut = -1)
{
if (timeOut == -1)
{
timeOut = this.waitTimeOut;
}
var wait = new WebDriverWait(WebDriver, TimeSpan.FromSeconds(timeOut));
wait.Until(ExpectedConditions.TitleIs(expectedPageTitle));
return true;
}

No comments:

Post a Comment