October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Use WebDriverWait in Selenium C#

A practical guide to Selenium C# WebDriverWait: write useful conditions, set timeouts, handle transient exceptions, and avoid fixed sleeps.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use WebDriverWait with a predicate that describes the browser state your next action needs. Selenium repeatedly evaluates that condition until it succeeds or the timeout expires, so you can wait for a result to appear instead of pausing for a fixed number of seconds.

What WebDriverWait does

WebDriverWait is an explicit wait for an IWebDriver. It is in the OpenQA.Selenium.Support.UI namespace, in the Selenium.WebDriver assembly, and derives from DefaultWait<IWebDriver>. Construct it with the driver and a TimeSpan, then call Until with a condition. Selenium WebDriverWait API

Unlike a fixed sleep, an explicit wait checks the condition repeatedly and returns as soon as it succeeds. That makes the condition—not an assumed page-load duration—the definition of readiness. Selenium waits guide

Basic C# example: wait for an element to be visible

This example waits up to 10 seconds for an element with the ID results to be displayed, then returns the element for the next test step.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;

var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement result = wait.Until(d =>
{
    var element = d.FindElement(By.Id("results"));
    return element.Displayed ? element : null;
});

The returned type is an IWebElement, so the successful condition can supply the object the test needs. Depending on the target framework and nullable-reference-type settings, your project may require a nullable annotation or other adjustment for the null return.

How Until decides the wait is complete

Until repeatedly passes the driver to the function you provide. A boolean condition succeeds when it returns true; an object-returning condition succeeds when it returns a non-null object. In either case, Until returns the successful result. If the condition throws an exception that is not configured to be ignored, that exception propagates. If the condition does not succeed before the timeout, the wait ends with a timeout failure. Selenium DefaultWait<T> API Selenium IWait<T> API

Wait for a boolean condition

If the next step only needs a condition to become true, return a boolean:

var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(d => d.FindElement(By.Id("revealed")).Displayed);

Selenium’s C# guide demonstrates this pattern with a two-second timeout. That value is an example, not a general recommendation; choose a timeout appropriate to the application and test environment. Selenium waits guide

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the state the next action actually needs

Finding an element establishes that it can be located; it does not establish that it is visible, interactable, or in the application-specific state your test needs. Make the predicate check the relevant condition. For example, use a visibility check before reading a visible result, or check a title or other application state when that is what indicates completion.

wait.Until(d => d.Title.Contains("Dashboard"));

Set the timeout, polling interval, and ignored exceptions

The standard constructor accepts an IWebDriver and a timeout. DefaultWait<T> documents defaults of 500 milliseconds for both its timeout and polling interval. In ordinary explicit-wait code, set the timeout in the WebDriverWait constructor rather than relying on the inherited default. The API also documents a constructor overload that accepts a clock and sleep interval. WebDriverWait API DefaultWait<T> API

Change the polling interval only when you have a reason to do so. A shorter interval means more frequent condition checks; it does not make an unsuitable condition meaningful. Selenium’s C# wait guide shows a 300-millisecond interval as an example, not a universal setting.

var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10))
{
    PollingInterval = TimeSpan.FromMilliseconds(300)
};

You can configure specific exception types to be ignored during polling. Ignore only errors that are expected to be transient for the condition you are checking:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10))
{
    PollingInterval = TimeSpan.FromMilliseconds(300)
};
wait.IgnoreExceptionTypes(typeof(ElementNotInteractableException));

Selenium uses ElementNotInteractableException in a guide example. It is not a blanket recommendation: exceptions outside the ignore list propagate, which helps expose real test failures instead of silently retrying them. Selenium waits guide DefaultWait<T> API

Use lambdas instead of Expected Conditions in Selenium 4 C#

Selenium’s documentation says, “.NET stopped supporting Expected Conditions in Selenium 4 to minimize maintenance hassle and redundancy.” Express the condition directly as a C# lambda passed to Until, as in the visibility and title examples above. Do not copy Expected Conditions examples intended for another Selenium language into a .NET test. Selenium Expected Conditions documentation

Keep implicit waits modest when using explicit waits

Selenium’s .NET timeout documentation warns that increasing the implicit wait can adversely affect runtime, particularly with slower element-location strategies. Avoid combining a large implicit wait with explicit waits without understanding the effects for your driver and test. The documentation does not establish a universal timing formula for the combination. Selenium ITimeouts API

Troubleshoot common wait failures

  • The wait times out although the element exists: Check that the locator matches the intended element and that the predicate tests the right state. Presence alone does not imply visibility or readiness for the next action.
  • The test fails immediately with an element exception: That exception may not be ignored by the wait. Fix an invalid locator or incorrect test assumption; add a narrow ignored exception only if it is expected to be transient for this condition.
  • The test continues before the page is ready: The predicate may be checking only for presence or another state that occurs too early. Wait for the state the application exposes when the desired operation is ready.
  • The test is slower than expected: Review the timeout, polling interval, duration of the condition itself, and any implicit wait configured on the driver. Selenium does not promise an exact total elapsed time based solely on the configured timeout.
  • The code does not compile with a nullable warning: The object-returning example uses null to mean “not ready yet.” Adapt its return annotation to the project’s target framework and nullable-reference-type settings.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is a website screenshot rather than a Selenium browser interaction, ScreenshotNeo can return an image or PDF with one GET request. Its clean-shot process accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the page verdict and billing status in headers. It also offers an MCP server for AI agents, including Claude and Cursor.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For setup and request options, see the ScreenshotNeo documentation. Replace the example URL with the page you want to capture:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Sign up for free ScreenshotNeo screenshots.

Frequently Asked Questions

Does WebDriverWait return the element when the wait succeeds?

Yes. If the condition returns a non-null object, Until returns that object; a boolean condition returns its successful result.

Can I use Selenium Expected Conditions in Selenium 4 for C#?

Selenium’s .NET support for Expected Conditions stopped in Selenium 4; use a lambda with Until instead.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.