ScreenshotNeo

BlogHow-to

How to Use Implicit Waits in Selenium C#

Set Selenium’s C# implicit wait with TimeSpan, understand what it waits for, and avoid slow or unpredictable tests.

By the ScreenshotNeo team4 October 20266 min read

Set an implicit wait on the Selenium WebDriver session through Manage().Timeouts():

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

After this setting, element-location calls wait up to two seconds for a match. The setting applies across the session; it does not wait for an element to become visible, clickable, or otherwise ready. Selenium’s documented default is zero, so a missing element otherwise fails immediately. Selenium’s waiting strategies explain the behavior and warn against mixing implicit and explicit waits.

1. Complete C# example

This example opens Selenium’s dynamic page, clicks the control that inserts an element, and locates the inserted element. Install the Selenium.WebDriver NuGet package and configure a ChromeDriver available to your environment before running it.

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

IWebDriver driver = new ChromeDriver();
try
{
    driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(2);

    driver.Navigate().GoToUrl("https://www.selenium.dev/selenium/web/dynamic.html");
    driver.FindElement(By.Id("adder")).Click();

    IWebElement added = driver.FindElement(By.Id("box0"));
    Console.WriteLine("Found the dynamically added element.");
}
finally
{
    driver.Quit();
}

The two-second value is an illustrative example, not a universal recommendation. Choose a limit that fits the delays your application can reasonably have.

2. How implicit wait behaves

ImplicitWait is a TimeSpan property on the .NET driver’s timeout settings. The driver applies it to element-location calls throughout the current session. A lookup returns as soon as it finds a match; if no match appears before the timeout expires, a single-element lookup raises NoSuchElementException. For a multi-element lookup, the driver waits until it finds at least one match or the timeout expires.

  • It waits for presence: the locator must find an element in the DOM.
  • It does not wait for readiness: presence does not guarantee visibility, enabled state, stable position, or successful interaction.
  • It is session-wide: a lookup in an unrelated part of the test can also incur the wait when it finds no match immediately.
  • It is not a fixed pause: a lookup returns early when it succeeds.
  • Zero is the default: without a configured wait, an unsuccessful lookup fails immediately.

3. Configure, change, or reset the timeout

Use a TimeSpan to set the duration. You can change the session setting later or reset it to zero:

using System;
using OpenQA.Selenium;

// Set a session-wide implicit wait of five seconds.
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);

// Reset to no implicit wait.
driver.Manage().Timeouts().ImplicitWait = TimeSpan.Zero;

The documented API accepts TimeSpan; construct the value with the unit that makes the intended duration clearest, such as FromMilliseconds or FromSeconds. Keep one consistent waiting strategy across the test suite so that lookup timing stays understandable.

4. Choose implicit or explicit wait

Use implicit wait when a modest session-wide allowance for delayed element presence is appropriate. Use an explicit wait when a particular test step depends on a particular state, such as visibility. Selenium describes explicit waits as polling for a specified condition and provides the C# WebDriverWait API for that approach.

Need Better fit Reason
Allow lookups to tolerate brief insertion delays across a session Implicit wait It applies to element-location calls globally.
Wait until one element is visible or another condition is true Explicit wait It targets a condition for a specific step.
Wait a fixed amount regardless of what the page does Usually neither A fixed sleep adds delay even when the page is already ready.

Do not mix implicit and explicit waits. Selenium warns that combining them can make total wait durations unpredictable. For example, a ten-second implicit wait combined with a fifteen-second explicit wait can result in a timeout after twenty seconds. If a test needs condition-based waits, set the implicit wait to zero and use explicit waits consistently.

For the official .NET interfaces and examples, see the ITimeouts API, the WebDriverWait API, and Selenium’s waiting strategies guide.

5. Common errors and fixes

Symptom Likely cause Fix
NoSuchElementException still occurs The locator never matches, the timeout is too short for the insertion delay, or the element is in a different browsing context. Verify the locator and page state first. Increase the timeout only if the element is expected to appear after a delay. Switch to the correct frame or window when applicable.
The element is found but interaction fails Implicit wait only ensures the lookup finds an element; it does not ensure the element is visible, enabled, or ready. Wait for the specific required condition with an explicit wait, and avoid mixing it with a nonzero implicit wait.
Tests take much longer after adding a wait Many unsuccessful lookups each wait, especially when repeated or using slower locator strategies such as XPath. Keep the global timeout modest, improve locators, and use a targeted explicit wait for condition-specific steps.
Observed timeout exceeds the configured duration A lookup may be part of a larger operation, or explicit and implicit waits may be combined. Remove the mixed wait configuration and use one strategy. Account for the number and sequence of lookups in the operation.
Wait assignment does not compile The value may be passed as a number instead of a TimeSpan, or required Selenium namespaces/packages are missing. Use TimeSpan.FromSeconds(...) or another TimeSpan factory and reference Selenium.WebDriver with using System;.

6. Runtime, reliability, and cost

An implicit wait does not add its full duration to every successful lookup. It can, however, add up across unsuccessful searches. Increasing it can slow a suite, particularly if tests frequently search for optional or absent elements. Locator efficiency matters too; Selenium’s .NET API advises increasing the setting judiciously.

For reliability, use stable locators, configure timeouts deliberately, and wait for the state the next action actually requires. A presence wait cannot fix a wrong locator, a page that failed to load, or an element hidden behind an overlay. Selenium itself has no per-wait charge described in the cited material; the practical cost here is test execution time and the compute used by your test environment.

7. Capture the page while debugging a Selenium flow

A screenshot can help inspect what the browser displayed when a lookup failed. You can capture one from your Selenium session using its browser APIs, or use a screenshot service when you need a separate capture request for a page.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server for developers. Make one GET request with the page URL to receive a PNG, JPEG, WebP, or PDF. See the API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://www.selenium.dev/selenium/web/dynamic.html -o shot.webp
import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://www.selenium.dev/selenium/web/dynamic.html"},
    timeout=90,
)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({
  access_key: 'YOUR_API_KEY',
  url: 'https://www.selenium.dev/selenium/web/dynamic.html'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
await Bun.write('shot.webp', res);

ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots. Sign up free for 1,000 screenshots a month with no card.

8. FAQ

Does implicit wait apply to every Selenium command?

No. It applies to element-location calls, not navigation, clicks, or arbitrary page conditions.

Does it wait for an element added by JavaScript?

Yes, if the locator eventually finds that element before the timeout. It does not establish that the element is ready for interaction.

What happens when FindElements finds nothing?

The lookup waits for at least one match up to the configured timeout, then returns an empty collection if none appears.

No. It is the example value in the official sample. Choose a timeout based on the application and test needs.