Wait Commands in Selenium C# : Implicit, Explicit & Fluent Waits

On This Page What is Wait Commands in Selenium?

April 01, 2026 · 10 min read · Tool Comparison

Wait Commands in Selenium C #: Implicit, Explicit & amp; Fluent Waits

A widely used open-source framework for automated testing is Selenium, which ensures that web covering run properly across all browsers and function systems. As a result, Selenium has get really democratic in the testing industry.

To essay our web applications best and resolve all challenge we face, it is important to learn certain while writing the test code. One of the well-nigh important factors in is the ability to use Wait commands to cut the.

Let & # 8217; s see how wait commands in Selenium C and C # facilitate us resolve time-lag topic in our web applications.

What is Wait Commands in Selenium?

are used in to handle the active loading of. Since some elements might have be make with the help of ajax or front-end frameworks, it direct some time for them to load, but since they haven & # 8217; t be loaded yet, running tests on them fails.

Selenium wait dictation break the tryout executing for a certain amount of time until those elements are ready in the DOM. As a result, our Selenium examination are more honest.

Types of Wait Commands in Selenium

The Selenium framework offers three types of hold commands for implementation.

Implicit Wait Command in C #

In Selenium C #,Implicit Waitis used to instruct the WebDriver to look for a sure sum of time before throwing an exception if it can not find an element. This wait is hold globally for all element, meaning the WebDriver will repeatedly check for the presence of an element in the DOM during the specified time period before go with the next step.

Implicit wait pauses the execution of the web driver for a specified period before drop any erroneousness. The specified time is base upon the time required by the web elements to get ready for the test, and thus get loaded on the page. However, the execution time of the overall test increases.

If the particular element takes more clip than what is specified, the Selenium web driver throws an error & # 8220;NoSuchElementException“.

The syntax for using the Implicit hold command in Selenium C # is as postdate.

driver.Manage () .Timeouts () .ImplicitWait = TimeSpan.FromSeconds (Value);

Let ’ s understand how to use implicit wait with the help of an example. In this example, we will navigate to Google ’ s homepage and will expect thither for 20 mo before execute the next step of our tryout. Moreover, this will also increase the execution clip by 20 moment.

habituate System; using OpenQA.Selenium; using OpenQA.Selenium.Chrome; namespace Test {class Program {Public stable nihility Main (draw [] args) {//Initialising ChromeDriver IWebDriver driver = new ChromeDriver (); //Navigating to Google 's homepage driver.Navigate () .GoToUrl (`` https: //www.google.com ``); //Applying Implicit Wait command for 20 seconds driver.Manage () .Timeouts () .ImplicitWait = TimeSpan.FromSeconds (20); //Clicking on an element after waiting for 20 seconds driver.FindElement (By.LinkText (`` I 'm Feeling Lucky '')) .Click ();}}}

When to Use Implicit Wait

  • For general waiting when you are timid about the consignment clip of elements.
  • For static page where elements are mostly available without too much delay.
  • When you require a simple, global wait configuration for all element searches.

When Not to Use Implicit Wait

  • When treat with dynamic web pages or AJAX calls where elements might load at different separation.
  • When precise control over look times is needed, such as waiting for specific conditions like, element visibility, Explicit Wait is preferred.

Explicit Wait Command in C #

In Selenium C #, anExplicit Waitis used to wait for a certain stipulation to occur before continue with further activeness. UnlikeImplicit Wait, which is applied globally,Explicit Waitis more targeted and allows you to wait for specific conditions to be met, such as an element get visible, clickable, or present.

Implicit Wait dictation, in Selenium C # waiting for a specific period. However, Explicit Wait in Selenium C # will await till certain weather come. The wait here for a web element is not for a specific period but till the web ingredient is ready in the DOM for testing. Explicit Wait C # is also known as & # 8220;smart waiting“.

The Explicit Wait bidding assure the precondition (element to become clickable, displayed, etc) every 250ms. Moreover, Implicit delay is solely applicable with methods, yet, Explicit Wait has several possible weather.

The Selenium Webdriver provides two classes for the execution of Explicit Wait.

  • WebDriverWait
  •  

The WebDriverWait calls the ExpectedConditionsform method until it returns successfully or the specified time is over. It is a major melioration for Implicit Wait, as there is no extra delay in the test.

The syntax for the custom of Explicit Wait is as follow

WebDriverWait wait = new WebDriverWait (driver, TimeSpan.FromSeconds (10)); wait.Until (ExpectedConditions.ElementExists (By.Id (`` id '')));

Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

In the above syntax,ElementExists ()is expend as a method, for example, nevertheless,ExpectedConditionsclass can contain several other methods also. Some of the mutual methods used are.

  • AlertIsPresent ()
  • ElementIsVisible ()
  • ElementExists ()
  • ElementToBeClickable (By)
  • ElementToBeClickable (IWebElement)
  • ElementToBeSelected (By)
  • TitleContains ()
  • UrlMatches ()
  • TextToBePresentInElementValue (IWebElement, String)
  • TextToBePresentInElement ()

Also-Read:

Now, let ’ s understand how to use the Explicit wait command in Selenium C # with the helper of an example.

To use Explicit waiting in your code, first install the following packages into your script.

  • OpenQA.Selenium.Support.UI& # 8211; It will help in action the WebDriverWait class
  • SeleniumExtras.WaitHelpers& # 8211; It will help execute ExpectedConditions class and its method into our test book.

In this test, the test will sail to the Gmail website, will fill up login point, and after signing in, we shall expect for the compose push to get laden, and once it is charge, the push will be clicked. After click the push, we shall wait for 20 minute with the help of Implicit Wait, and then will close the browser.

utilise System; using NUnit.Framework; using OpenQA.Selenium; use OpenQA.Selenium.Chrome; using OpenQA.Selenium.Support.UI; utilize SeleniumExtras.WaitHelpers; employ System; namespace ExplicitWait {class ExplicitWait {IWebDriver driver; [SetUp] public void open_gmail () {driver = new ChromeDriver (); driver.Manage () .Window.Maximize ();} [Test] public nothingness login_and_wait () {String email_site = `` https: //gmail.com ''; driver.Url = email_site; IWebElement Email = driver.FindElement (By.Id (`` Email '')); Email.SendKeys (`` your_username ''); Email.SendKeys (Keys.Return); IWebElement Password = driver.FindElement (By.Id (`` Email '')); Password.SendKeys (`` your_password ''); Password.SendKeys (Keys.Return); driver.FindElement (By.Id (`` signIn '')) .Click (); String xpath = `` //div [contains (text (), 'COMPOSE ')] ''; WebDriverWait wait = new WebDriverWait (driver, TimeSpan.FromSeconds (10)); IWebElement ComposeButton = wait.Until (ExpectedConditions.ElementExists (By.XPath (xpath))); ComposeButton.Click (); driver.Manage () .Timeouts () .ImplicitWait = TimeSpan.FromSeconds (30);} [TearDown] public void close_Browser () {driver.Quit ();}}}

When to Use Explicit Wait in Selenium C #

  • Waiting for specific conditions: When you need to wait for elements to get visible, clickable, or meet other conditions.
  • Dynamic content: For pages where elements load asynchronously (e.g., AJAX, JavaScript).
  • Avoiding cold elements: When you want to assure an component is present before interacting with it.
  • Waiting for page transitions: When the page content changes dynamically (e.g., after form entry or navigation).
  • Optimized test stableness: To handle scenarios where postponement are unpredictable or elements are hidden for some time.

When Not to Use Explicit Wait in Selenium C #

  • Stable substance: When elements are incessantly useable and don ’ t change dynamically.
  • Short tryout case: For simple interactions where elements are readily uncommitted, using explicit wait may slow down tests unnecessarily.
  • Global hold: When the same expect condition applies to all elements, an implicit hold may be more efficient.
  • Overusing waits: When employ explicit waits on every element unnecessarily leads to bloated code and slower exam.
  • Simple element retrieval: For contiguous access to elements when no delay is expected like, during initialization or setup.

There are a few exceptional situation occurs, which hap while the driver searches for the web element in the DOM. However, if you want to dismiss these errors while await for some condition to occur,IgnoreExceptionTypes ()method is used. A few such error situation are as follow.

  • NoSuchElementException
  • StateElementReferenceException
  • ElementNotVisibleException
  • ElementNotSelectableException
  • NoSuchFrameException

Read More:

The syntax while using Explicit Wait is as follows:

WebDriverWait wait = new WebDriverWait (driver, TimeSpan.FromSeconds (10)); wait.IgnoreExceptionTypes (typeof (ElementNotSelectableException));

Talk to an Expert

Fluent Wait Command in C #

In Selenium C #,Fluent Waitis a more flexible version of explicit delay that allows you to define not but the maximum wait time but also the frequency with which the precondition should be checked. It provides great control, such as the ability to cut specific exclusion such as.,NoSuchElementExceptionduring the wait period.

Fluent Wait command in Selenium C # is alike to Explicit Wait in so many aspects. It allows you to control the Web Driver to set the specified time for some status to seem before it could throw the error “ ElementNotVisibleException ”.

The master advantage of implementing the Fluent Wait bid is specify the polling oftenness. Polling frequency is the frequency at which the driver cheque for the element whether it has loaded or not. It has the attribute .pollingfrquency, and its nonpayment value is 500ms, which entail the driver will check every 500 milliseconds before throwing the fault.

The syntax for the custom of Fluent Wait is as follows:

DefaultWait & lt; IWebDriver & gt; fluentWait = new DefaultWait & lt; IWebDriver & gt; (driver); fluentWait.Timeout = TimeSpan.FromSeconds (5); fluentWait.PollingInterval = TimeSpan.FromMilliseconds (polling_interval_in_ms);

Let ’ s understand Fluent Wait with the help of an example, demonstrating the previous instance where the driver waits for the compose button to seem in Gmail. In this example, there is a wait of 5 seconds and a polling frequency of 250ms.

utilize System; using NUnit.Framework; using OpenQA.Selenium; expend OpenQA.Selenium.Chrome; using OpenQA.Selenium.Support.UI; using SeleniumExtras.WaitHelpers; using System; namespace Selenium_ExplicitWait_Demo {class Selenium_ExplicitWait_Demo {IWebDriver driver; [SetUp] public vacancy open_gmail () {driver = new ChromeDriver (); driver.Manage () .Window.Maximize ();} [Test] public void login_and_wait () {DefaultWait & lt; IWebDriver & gt; fluentWait = new DefaultWait & lt; IWebDriver & gt; (driver); fluentWait.Timeout = TimeSpan.FromSeconds (5); fluentWait.PollingInterval = TimeSpan.FromMilliseconds (250); String email_site = `` https: //gmail.com ''; driver.Url = email_site; IWebElement Email = driver.FindElement (By.Id (`` Email '')); Email.SendKeys (`` your_username ''); Email.SendKeys (Keys.Return); IWebElement Password = driver.FindElement (By.Id (`` Email '')); Password.SendKeys (`` your_password ''); Password.SendKeys (Keys.Return); driver.FindElement (By.Id (`` signIn '')) .Click (); String xpath = `` //div [contains (text (), 'COMPOSE ')] ''; IWebElement ComposeButton = fluentWait.Until (dom = & gt; dom.FindElement (By.XPath (xpath))); ComposeButton.Click (); driver.Manage () .Timeouts () .ImplicitWait = TimeSpan.FromSeconds (30);} [TearDown] public void close_Browser () {driver.Quit ();}}}

When to Use Fluent Wait in Selenium C #:

  • Need for polling control: When you need to check for an element at specific separation (such as, every 500 milliseconds).
  • Handling dynamic content: For pages where elements may appear intermittently or after varying delays.
  • Ignoring specific exclusion: When you require to discount exceptions likeNoSuchElementExceptionduring the waiting.
  • Long wait times with frequent checks: When the expected condition takes time, but you want to avoid continuously checking without hold.
  • Complex delay scenarios: When you need great flexibleness in waiting for multiple conditions or types of exceptions.

When Not to Use Fluent Wait in Selenium C #

  • Simple scenarios: When component are require to be available immediately or within a short, predictable time.
  • Performance-sensitive cases: When excessive polling and delays may negatively impact test execution speed.
  • World postponement: When the same wait condition applies to all elements (in such cases,ImplicitWaitis more efficient).
  • No dynamic content: When the page is static and all factor are promptly available with no wait.
  • Frequent little waits: When there ’ s no need to check repeatedly for a condition, and a one-time explicit wait suffices.

However, the syntax for ignoring exceptions while using Fluent Wait is as follows:

fluentWait.IgnoreExceptionTypes (typeof (ElementNotSelectableException));

Why use BrowserStack Automate for Selenium C # Tests?

Here ’ s why you should use to run Selenium C # Tests:

  • : BrowserStack Automate countenance you to run tests simultaneously on several devices and browsers, cut execution clip and provide faster feedback.
  • Real Devices and Browsers: Testing on actual devices and browser afford a true picture of your app ’ s execution, unlike emulators. You can admission the modish devices without needing to purchase them.
  • Dedicated Dashboard: Automate provide a dashboard to supervise and deal your trial. It displays test results (Pass/Fail/Pending), device and browser details, trial length, screenshots, and more.
  • Custom Reports with Artifacts: Create detailed and customizable reports that include test resolution, gimmick and browser configurations, video recordings, and screenshots.
  • Seamless CI/CD Integration: Easily integrate with CI/CD tools like Jenkins, TeamCity, and TravisCI, ensuring faster and more reliable coating speech.

Conclusion

In this tutorial, we understood how some web elements could occupy more time to load than others. This happens when the web ingredient are built using Ajax or any front-end framework. However, this stimulate hindrance in our examination, and thusly, we don ’ t get a flawless testing experience.

Therefore, Wait require play an crucial role in Selenium mechanisation testing to resolve this as it pauses the test until we get the specific ready for testing in the DOM; yet, it also increases the time of executing of our tests.

BrowserStack ’ s crack 3500+ existent devices and browser for automated testing. Users can run tests on multiple real devices and browsers by simply signing up, logging in, and selecting the needful combination

Tags
85,000+ Views

# Ask-and-Contributeabout this topic with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free