Selenium with C Sharp - How to perform Explicit Wait method?

We can perform explicit wait with Selenium webdriver in C#. This is done to achieve synchronization between our tests and the elements on the page. For implementation of explicit wait, we have to take the help of the WebDriverWait and ExpectedCondition classes.

We shall create an object of the WebDriverWait class. The webdriver waits tillspecified wait time waiting for the expected condition for an element is satisfied.

After the time has elapsed, an exception is raised by Selenium.

The explicit waits are dynamic in nature which means if we have an explicit wait of five seconds and the expected condition is met at the third second, then the webdriver shall move to the next step immediately. It does not wait till the entirefive seconds.

Some of the expected conditions are −

  • UrlToBe

  • VisibilityOfAllElementsLocatedBy

  • UrlContains

  • AlertIsPresent

  • AlertState

  • ElementToBeSelected

  • ElementIsVisible

  • ElementExists

  • ElementSelectionStateToBe

  • ElementToBeClickable

  • InvisibilityOfElementWithText

  • InvisibilityOfElementLocated

  • TextToBePresentInElementLocated

  • TextToBePresentInElementValue

  • TextToBePresentInElement

  • StalenessOf

  • TitleContains

  • FrameToBeAvailableAndSwitchToIt

  • PresenceOfAllElementsLocatedBy

  • TitleIs


WebDriverWait w =
new WebDriverWait(driver, TimeSpan.FromSeconds(20));

Let us try to wait for the text - Team @ Tutorials Point to be visible on the page −


using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
namespace NUnitTestProject2{
   public class Tests{
      String url = "";
      IWebDriver driver;
      public void Setup(){
         //creating object of FirefoxDriver
         driver = new FirefoxDriver("");
      public void Test2(){
         //URL launch
         //identify element then click
         IWebElement t = driver.FindElement(By.XPath("//*[text()='Team']"));
         //expected condition of Element visibility
         WebDriverWait w = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
         //identify element then obtain text
         IWebElement n = driver.FindElement(By.TagName("h1"));
         Console.WriteLine("Text is: " + n.Text);
      public void close_Browser(){