WebDriverException
WebDriverException: Causes and Fixes
Fix Selenium WebDriverException (WebDriverError in JS): chrome not reachable, connection refused, unknown error, net::ERR messages and client HTTP timeouts.
| Java | org.openqa.selenium.WebDriverException |
|---|---|
| Python | selenium.common.exceptions.WebDriverException |
| JavaScript | WebDriverError |
| C# | OpenQA.Selenium.WebDriverException |
What the error means
WebDriverException is the base class for every Selenium error. All the specific exceptions on this site (NoSuchElementException, TimeoutException and the rest) extend it. When you see the plain WebDriverException, it means no more specific type fits: usually the W3C unknown error code, a driver crash, or a failure in the HTTP connection between your client and the driver.
So the class name tells you almost nothing. The message tells you everything. Group your diagnosis by the first line of the message:
| Message starts with | Where the problem is |
|---|---|
unknown error: net::ERR_... | The browser could not load the URL |
unknown error: cannot find Chrome binary / no chrome binary | Browser not installed where the driver looks |
chrome not reachable / disconnected: not connected to DevTools | The browser process died or hung |
Connection refused / Could not start a new session / ECONNREFUSED | The driver or Grid is not listening |
Read timeout / SocketTimeoutException | A command took longer than the client’s HTTP timeout |
What it looks like
// Java: navigation failureorg.openqa.selenium.WebDriverException: unknown error: net::ERR_CONNECTION_REFUSED (Session info: chrome=131.0.6778.86)# Python: browser died mid-testselenium.common.exceptions.WebDriverException: Message: disconnected: not connected to DevTools (failed to check if window was closed: disconnected: not connected to DevTools) (Session info: chrome=131.0.6778.86)// JavaScript (selenium-webdriver): driver not runningError: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:4444// C#: HTTP timeout to the driverOpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:52713/session/8d1c.../url timed out after 60 seconds. ----> System.Threading.Tasks.TaskCanceledException : The request was canceled due to the configured HttpClient.Timeout of 60 seconds elapsing.In Java, an HTTP read timeout shows up with a java.net.http.HttpTimeoutException or similar in the cause chain; in Python, network-level failures between client and driver often surface as urllib3 exceptions (MaxRetryError, ReadTimeoutError) rather than WebDriverException.
Common causes
- The application under test is not reachable.
net::ERR_CONNECTION_REFUSED,ERR_NAME_NOT_RESOLVED, orERR_CERT_AUTHORITY_INVALIDbecause the app is down, the URL is wrong, orlocalhostmeans something different inside a container. - The browser crashed or hung. Memory pressure, a small
/dev/shm, a renderer crash, or a modal native dialog freezing the browser. - The driver or Grid is not running or not reachable. Wrong remote URL, wrong port, the Grid is still starting, or a firewall in between.
- A command exceeded the client HTTP timeout. A very slow page load or script outlasted the client’s read timeout.
- The browser binary cannot be found. A custom install location or a container without the browser.
How to fix it
The application under test is not reachable
Open the same URL from the machine (or container) where the browser runs, for example with curl. In Docker, localhost inside the browser container is the container itself, not your host: use the service name on a shared network, or host.docker.internal where supported. For self-signed certificates in test environments, accept insecure certificates explicitly.
ChromeOptions options = new ChromeOptions();options.setAcceptInsecureCerts(true);WebDriver driver = new ChromeDriver(options);options = webdriver.ChromeOptions()options.accept_insecure_certs = Truedriver = webdriver.Chrome(options=options)const chrome = require('selenium-webdriver/chrome');const options = new chrome.Options().setAcceptInsecureCerts(true);const driver = await new Builder().forBrowser('chrome').setChromeOptions(options).build();var options = new ChromeOptions { AcceptInsecureCertificates = true };var driver = new ChromeDriver(options);The browser crashed or hung
Messages like chrome not reachable, disconnected: not connected to DevTools and session deleted because of page crash mean the browser went away. In containers, raise shared memory (--shm-size=2g) or add --disable-dev-shm-usage, run fewer browsers per host, and run headless. Turn on driver logging to see what Chrome printed before it died; see browser and driver logs. After a crash the session is usually unusable, and the next command fails with InvalidSessionIdException.
The driver or Grid is not running or not reachable
Check the remote URL and that the Grid is ready before tests start. Grid exposes a status endpoint (/status) whose ready field you can poll from your CI script. Wait for it rather than starting tests the moment the container starts.
URL gridUrl = URI.create(System.getenv().getOrDefault("GRID_URL", "http://localhost:4444")).toURL();WebDriver driver = new RemoteWebDriver(gridUrl, new ChromeOptions());import os
grid_url = os.environ.get("GRID_URL", "http://localhost:4444")driver = webdriver.Remote(command_executor=grid_url, options=webdriver.ChromeOptions())const chrome = require('selenium-webdriver/chrome');const gridUrl = process.env.GRID_URL || 'http://localhost:4444';const driver = await new Builder().usingServer(gridUrl).forBrowser('chrome').setChromeOptions(new chrome.Options()).build();var gridUrl = new Uri(Environment.GetEnvironmentVariable("GRID_URL") ?? "http://localhost:4444");var driver = new RemoteWebDriver(gridUrl, new ChromeOptions());Note that Grid 4 does not need the old /wd/hub suffix, although it still accepts it.
A command exceeded the client HTTP timeout
The client gives up on a single HTTP request after its own timeout (commonly 60 seconds in .NET, configurable in every binding). If a page load timeout or script timeout is set higher than that, the client times out first with a confusing low-level error. Keep page load and script timeouts below the client HTTP timeout so you get a clear TimeoutException instead. In .NET you can pass a longer command timeout to the driver constructor; Java’s ClientConfig and Python’s ClientConfig offer the same control for remote sessions.
The browser binary cannot be found
Install the browser, or let Selenium Manager download one by setting a browser version in options (see SessionNotCreatedException). For a non-standard install location, set the binary path in options (setBinary in Java, binary_location in Python, setChromeBinaryPath in JavaScript, BinaryLocation in C#).
How to prevent it
- Health-check the application and the Grid before the suite starts, and fail fast with a clear message if either is down.
- Run browsers in properly sized containers using the official Selenium images.
- Keep browser-side timeouts lower than the client HTTP timeout.
- Log the full message and cause chain on failure, not just the exception class; the class is always the same.
- Keep the Selenium client current; many “unknown error” crashes are fixed driver and client bugs.
Related errors
- SessionNotCreatedException: the specific error for failures while starting the browser.
- InvalidSessionIdException: what follows once a crashed browser’s session is cleaned up.
- TimeoutException: browser-side timeouts with clear messages.
- JavascriptException: errors from your own scripts, reported with their own type.
Go deeper
- Browser and Driver Logs Turn on the logs that explain failures: browser console output via BiDi, chromedriver and geckodriver logs, Selenium's own client logging, network failures, and how to collect them per test.
- How WebDriver Works: Architecture and Protocol What actually happens when you call driver.findElement(): the client binding, the W3C WebDriver protocol, the browser driver, sessions, and where BiDi and Grid fit in.
- Docker and Testcontainers Run browsers in the official Selenium Docker images, compose a Grid with video recording, and use Testcontainers to start a disposable browser per test from Java, Python, .NET or Node.
- Debugging Tips Essential techniques for debugging Selenium tests, identifying failures, and fixing flaky tests.