TimeoutException
TimeoutException: Causes and Fixes
Fix Selenium TimeoutException (TimeoutError in JS, WebDriverTimeoutException in C#): failed explicit waits, page load and script timeouts, implicit wait mixing.
| Java | org.openqa.selenium.TimeoutException |
|---|---|
| Python | selenium.common.exceptions.TimeoutException |
| JavaScript | TimeoutError |
| C# | OpenQA.Selenium.WebDriverTimeoutException |
What the error means
Something did not finish within the time you allowed. In practice there are three different timeouts that share this exception family, and the fix depends on which one fired:
| Source | Thrown by | Typical message |
|---|---|---|
Explicit wait (WebDriverWait) | The client library, after polling a condition | “Expected condition failed…” / “Wait timed out after…” |
| Page load timeout | The browser driver, during get() or a navigation | “timeout: Timed out receiving message from renderer” |
| Script timeout | The browser driver, during executeAsyncScript | “script timeout” |
The explicit wait case is by far the most common. It is not an error in the wait; the wait is reporting that your condition never became true. The question is always why not.
What it looks like
// Java: explicit waitorg.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.id: results (tried for 10 second(s) with 500 milliseconds interval)Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#results"}# Python: explicit wait (note the empty message by default)Traceback (most recent call last): File "test_search.py", line 21, in test_results WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, "results"))) File ".../selenium/webdriver/support/wait.py", line ..., in until raise TimeoutException(message, screen, stacktrace)selenium.common.exceptions.TimeoutException: Message:// JavaScript (selenium-webdriver)TimeoutError: Waiting for element to be located By(css selector, #results)Wait timed out after 10014ms// C#OpenQA.Selenium.WebDriverTimeoutException : Timed out after 10 seconds ----> OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element: {"method":"css selector","selector":"#results"}// Page load timeout (Java shown)org.openqa.selenium.TimeoutException: timeout: Timed out receiving message from renderer: 299.512In Java and C#, read the cause / inner exception. It usually tells you what the last poll saw: element missing, element present but hidden, stale reference.
Common causes
- The condition is wrong for what you need. Waiting for visibility of an element that is never visible (a hidden input), or for text that differs slightly (whitespace, case).
- The locator is wrong, so the wait was polling for something that will never exist.
- The application is genuinely slow or broken. An API call failed, the spinner never stopped, an error banner appeared instead.
- Implicit and explicit waits are mixed, so each poll blocks for the implicit timeout and the effective wait time balloons.
- The page load never completes. A slow third-party script, analytics beacon or long-polling connection keeps the
loadevent from firing. - An async script never called its callback, producing a script timeout.
How to fix it
The condition is wrong for what you need
Pick the condition that matches the user-visible state you need, and add a message so the failure explains itself.
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));wait.withMessage("search results panel never showed 'results for shoes'");wait.until(ExpectedConditions.textToBePresentInElementLocated( By.id("results-heading"), "results for shoes"));wait = WebDriverWait(driver, 10)wait.until( EC.text_to_be_present_in_element((By.ID, "results-heading"), "results for shoes"), message="search results panel never showed 'results for shoes'")const heading = await driver.wait(until.elementLocated(By.id('results-heading')), 10000);await driver.wait(until.elementTextContains(heading, 'results for shoes'),10000,"search results panel never showed 'results for shoes'");var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)){ Message = "search results panel never showed 'results for shoes'"};wait.Until(d => d.FindElement(By.Id("results-heading")).Text.Contains("results for shoes"));Python’s default empty message is the single biggest reason people cannot diagnose these failures. Always pass message=.
The locator is wrong
Copy the locator from the failure message into the DevTools Elements search (Ctrl+F) on the page at the moment of failure. A screenshot and page source captured on failure make this possible after the fact.
The application is genuinely slow or broken
Look at the screenshot first. If there is an error toast or a spinner, the test found a real problem or an environment problem. Do not just raise the timeout; check the browser console and network logs (see browser and driver logs). If the operation really is slow (report generation, file processing), give that one wait a longer budget rather than raising the global default.
Implicit and explicit waits are mixed
Set the implicit wait to zero when you use explicit waits. With an implicit wait of 10 seconds, every findElement inside a 10-second explicit wait can block for 10 seconds, so the wait may run for 20 seconds or more before reporting.
driver.manage().timeouts().implicitlyWait(Duration.ZERO);driver.implicitly_wait(0)await driver.manage().setTimeouts({ implicit: 0 });driver.Manage().Timeouts().ImplicitWait = TimeSpan.Zero;The page load never completes
Either raise the page load timeout for that environment, or change the page load strategy so get() returns earlier and your explicit waits handle readiness. eager returns at DOMContentLoaded, which is usually enough when you wait for specific elements anyway.
ChromeOptions options = new ChromeOptions();options.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriver driver = new ChromeDriver(options);driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(60));options = webdriver.ChromeOptions()options.page_load_strategy = "eager"driver = webdriver.Chrome(options=options)driver.set_page_load_timeout(60)const chrome = require('selenium-webdriver/chrome');const options = new chrome.Options().setPageLoadStrategy('eager');const driver = await new Builder().forBrowser('chrome').setChromeOptions(options).build();await driver.manage().setTimeouts({ pageLoad: 60000 });var options = new ChromeOptions { PageLoadStrategy = PageLoadStrategy.Eager };var driver = new ChromeDriver(options);driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(60);Blocking slow third-party hosts with BiDi network interception is another strong option in test environments; see the page load strategy lesson.
An async script never called its callback
executeAsyncScript waits until the script calls the callback passed as its last argument (arguments[arguments.length - 1]). If any code path forgets to call it, or a promise rejects without handling, you hit the script timeout (30 seconds by default). Make sure every branch, including errors, calls the callback. Java reports this as ScriptTimeoutException and JavaScript as ScriptTimeoutError.
How to prevent it
- One budget per wait type: a short default (5 to 10 seconds) for UI waits, explicit longer waits for known slow operations.
- Always attach a message describing the expected state.
- Keep implicit waits at zero.
- Capture screenshot, page source and console logs on failure so a timeout is diagnosable without a re-run.
- Write custom wait conditions for app-specific readiness signals (spinner gone, network idle flag) instead of chaining generic ones.
Related errors
- NoSuchElementException: usually the cause wrapped inside a wait timeout.
- StaleElementReferenceException: a wait polling a captured element that was replaced.
- JavascriptException: a script failed outright instead of timing out.
- WebDriverException: HTTP read timeouts between client and driver surface as generic WebDriver errors.
Go deeper
- Explicit Waits Learn to use explicit waits in Selenium to handle dynamic content and avoid flaky tests.
- Implicit Waits Understand implicit waits, their global behavior, and when to use them versus explicit waits.
- Page Load Strategy and Timeouts Control when driver.get() returns with normal, eager and none strategies, set the three session timeouts (page load, script, implicit), and combine them with explicit waits for fast, stable tests.
- Custom Wait Conditions Write your own expected conditions with lambdas and classes, wait for attribute and text changes, element counts, JavaScript state, network idleness via BiDi, and compose conditions cleanly.