Saturday, 23 May 2015

Explicit Wait Conditions in Selenium Webdriver

We have below wait conditions in Selenium C# API.

  1. Wait until Element exists in page
  2. Wait until Element becomes visible on page
  3. Wait until page title becomes as expected

Below code waits for element with ID login until it exists. Please note that timeOut variable contains total number of seconds you need to wait.

new WebDriverWait(driver, TimeSpan.FromSeconds(timeOut)).Until(ExpectedConditions.ElementExists((By.Id(login))));
Below code waits for element with ID login until it gets visible on the page
new WebDriverWait(driver, TimeSpan.FromSeconds(timeOut)).Until(ExpectedConditions.ElementIsVisible((By.Id(login))));
Below code waits until Page title becomes Yahoo News
new WebDriverWait(driver, TimeSpan.FromSeconds(timeOut)).Until(ExpectedConditions.TitleIs("Yahoo News"));
Below code waits until Page title contains News word
 new WebDriverWait(driver, TimeSpan.FromSeconds(timeOut)).Until(ExpectedConditions.TitleContains("News"));

In Selenium-Java API, we have more such conditions like wait until the element is refreshed, wait  until the element is hidden or wait until text value of the element becomes as expected.

What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at reply2sagar@gmail.com

No comments:

Post a Comment

Buy Best Selenium Books