C# and Selenium: Wait Until Element is Present

SeleniumCsharpAutomation TestingTesting Tools

We can wait until an element is present in Selenium webdriver using the explicit wait. It is mainly used whenever there is a synchronization issue for an element to be available on page.

The WebDriverWait and the ExpectedCondition classes are used for an explicit wait implementation. We have to create an object of the WebDriverWait which shall invoke the methods of the ExpectedCondition class.

The webdriver waits for a specified amount of time for the expected criteria to be met. After the time has elapsed, an exception gets thrown. To wait for an element to be present, we have to use the expected condition – ElementExists.


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

Let us try to wait for the text - About Careers at Tutorials Point to be available 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 ="https://www.tutorialspoint.com/about/about_careers.htm";
      IWebDriver driver;
      public void Setup(){
         //creating object of FirefoxDriver
         driver = new FirefoxDriver("");
      public void Test2(){
         //URL launch
         //identify element then click
         IWebElement l = driver.FindElement(By.XPath("//*[text()='Careers']"));
         //expected condition of ElementExists
         WebDriverWait w = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
         //identify element then obtain text
         IWebElement m = driver.FindElement(By.TagName("h1"));
         Console.WriteLine("Element text is: " + m.Text);
      public void close_Browser(){


Published on 07-Apr-2021 12:14:27