How to Use ChromeDriver with Selenium for Browser Automation
Set up Selenium 4 with ChromeDriver, choose automatic or manual driver management, and fix common browser automation errors.
Direct answer: Install Selenium 4 and Google Chrome, then create a Chrome WebDriver session with Selenium’s Chrome options. When you do not provide a driver path, Selenium Manager can locate, download, and cache a compatible ChromeDriver for you. For most local setups, that is the simplest starting point.
ChromeDriver is the browser-specific driver Selenium uses to communicate with Chrome. Selenium 4’s Chrome guide says Chrome and ChromeDriver should have matching major versions. If automatic driver discovery does not fit your environment, you can put a compatible driver on PATH or provide its path explicitly.
1. Understand Selenium, Chrome, and ChromeDriver
Selenium WebDriver sends browser automation commands through a browser-specific driver. For Chrome, that component is ChromeDriver. The driver starts and controls Chrome; your Selenium code interacts with the WebDriver session rather than controlling the browser directly.
Selenium’s Chrome guide describes default compatibility with Chrome 75 and greater and says the browser and driver major versions must match. Selenium Manager, shipped with Selenium releases starting at 4.6, can resolve and cache a driver when one is not supplied. Selenium 4.11.0 added management of Chrome for Testing browsers; that is distinct from the ordinary setup where Selenium Manager obtains a driver for Chrome already installed on your machine.
2. Choose how to manage ChromeDriver
| Approach | Setup and upkeep | Best fit |
|---|---|---|
| Selenium Manager fallback | Low effort in a typical current Selenium setup. It resolves and caches a driver; initial resolution may need network access. | Start here for local automation. |
Manual driver on PATH or explicit path |
You obtain the driver and keep its major version compatible with Chrome. | Custom installations, pinned environments, or cases the manager cannot handle. |
| Selenium Grid or remote WebDriver | Requires a remote execution environment and browser-node administration. | Distributed runs across machines or operating systems. |
Use Selenium Manager first unless your environment has a specific reason to pin or locate the driver yourself. Manual pinning transfers version upkeep to you: a Chrome update can leave the selected driver behind. Grid addresses distributed execution; it is a separate deployment decision from local ChromeDriver setup.
3. Install Selenium and start Chrome
Install the Selenium binding for your language and ensure Chrome is available. The examples below use Selenium 4. They leave driver discovery to Selenium Manager by not supplying a driver executable path.
Python
python -m pip install -U selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
# Add Chrome startup arguments here only when your environment requires them.
driver = webdriver.Chrome(options=options)
try:
driver.get("https://example.com")
print("Title:", driver.title)
print("URL:", driver.current_url)
finally:
driver.quit()
Java
Add Selenium 4 to your project’s dependencies, then create a session with ChromeOptions:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class ChromeAutomation {
public static void main(String[] args) {
ChromeOptions options = new ChromeOptions();
WebDriver driver = new ChromeDriver(options);
try {
driver.get("https://example.com");
System.out.println("Title: " + driver.getTitle());
System.out.println("URL: " + driver.getCurrentUrl());
} finally {
driver.quit();
}
}
}
JavaScript
Install the Selenium JavaScript package, then create a Chrome session:
npm install selenium-webdriver
const { Builder, Browser } = require('selenium-webdriver');
(async function main() {
const driver = await new Builder().forBrowser(Browser.CHROME).build();
try {
await driver.get('https://example.com');
console.log('Title:', await driver.getTitle());
console.log('URL:', await driver.getCurrentUrl());
} finally {
await driver.quit();
}
})();
4. Configure Chrome with options
In Selenium 4, configure browser startup through the browser’s options class: Options in Python and ChromeOptions in Java. JavaScript’s builder can also receive Chrome options. Options are useful for headless runs, setting browser arguments, or requesting a browser version from a remote end. Keep configuration specific to the environment instead of copying flags blindly.
Headless Chrome in Python
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--headless")
driver = webdriver.Chrome(options=options)
try:
driver.get("https://example.com")
print(driver.title)
finally:
driver.quit()
Chrome startup arguments can affect security and behavior. For example, do not add --no-sandbox to a general-purpose script by default; only use environment-specific flags when your deployment requires them.
Request a browser version
browserVersion is an optional capability. It is most relevant when a remote end or a Selenium setup managing Chrome for Testing can provide the requested version. Recent Selenium can use Selenium Manager to obtain a requested browser that is not present locally. A version request does not make an arbitrary locally installed Chrome and manually pinned ChromeDriver compatible.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.set_capability("browserVersion", "stable")
driver = webdriver.Chrome(options=options)
try:
driver.get("https://example.com")
print(driver.capabilities)
finally:
driver.quit()
Use a version value supported by the Selenium endpoint you are connecting to. For a remote session, configure the remote WebDriver URL and capabilities according to that Grid or provider’s documentation.
5. Manage ChromeDriver explicitly when needed
If you cannot use Selenium Manager’s default resolution, install a ChromeDriver build compatible with your Chrome installation. Keep the driver executable discoverable on PATH, or pass its path through the binding’s service API. The exact service class depends on the language.
Python with an explicit path
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
service = Service(executable_path="/absolute/path/to/chromedriver")
options = Options()
driver = webdriver.Chrome(service=service, options=options)
try:
driver.get("https://example.com")
print(driver.title)
finally:
driver.quit()
Replace the example path with the driver executable’s actual location. Confirm that it is executable and that its major version matches Chrome’s. Manual paths are useful for controlled environments, but someone must update the pinned driver when the browser changes.
6. Automate a page reliably
Starting the browser is only the first step. Wait for the page state or element your task depends on instead of relying on a fixed sleep. Always close the session in a finally block so failures do not leave browser processes running.
Wait for an element in Python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.options import Options
options = Options()
driver = webdriver.Chrome(options=options)
try:
driver.get("https://example.com")
heading = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.TAG_NAME, "h1"))
)
print(heading.text)
finally:
driver.quit()
Choose a wait condition that matches the action: presence for DOM availability, visibility before reading or interacting, and clickability before clicking. A timeout can mean the selector is wrong, the page did not finish the expected transition, or the site never reached the expected state.
7. Troubleshoot common ChromeDriver errors
| Symptom | Likely cause | What to do |
|---|---|---|
| Unable to locate driver | No usable driver was found, Selenium is old, or automatic resolution could not complete. | Check the Selenium version, network/proxy access, and driver availability. With a current Selenium binding and no supplied driver, Selenium Manager is the fallback. Enable Selenium’s driver-location logging and inspect its diagnostics before changing versions. |
| “This version of ChromeDriver only supports Chrome version 113” | The example indicates a browser and driver major-version mismatch; 113 is illustrative, not a statement about current releases. | Check the installed Chrome major version and use a matching ChromeDriver, or remove an unnecessary manual driver path so Selenium Manager can resolve one. |
| Selenium Manager cannot download metadata or a driver | Network access, proxy configuration, or download restrictions prevent resolution. | Check outbound access and proxy settings for the Selenium process. In restricted environments, provision a compatible driver locally and pass its path. |
| Driver exists but will not start | Wrong executable path, permissions, architecture, or an unsupported custom build. | Verify the file path and execute permission, confirm the machine architecture/build is supported, and check browser-driver compatibility. |
| Chrome opens and exits or a command fails | Browser startup configuration, lifecycle handling, or an application-specific page condition may be wrong. | Temporarily remove nonessential startup flags, capture the exception, use explicit waits, and call quit() in cleanup. |
| Works locally but not on Grid | The remote browser node controls the browser and driver; local paths do not necessarily exist there. | Configure the Grid endpoint and capabilities for the node environment. Do not pass a workstation’s driver path expecting the remote node to use it. |
Selenium’s current driver-location guidance recommends enabling logging when a current setup still cannot locate a driver. The diagnostic output helps distinguish a missing executable from a failed manager lookup or a custom-location issue.
8. Performance, reliability, and cost
Launching a new browser session has setup cost. For repeated work, reuse a session when tasks can safely share browser state, and close it when the batch ends. For parallel or cross-platform suites, Selenium Grid is the documented route to distributed execution; capacity then depends on the Grid and its browser nodes.
Selenium Manager caches resolved drivers, reducing repeated downloads after a successful resolution. First-time setup can still depend on network and platform constraints. Pinning browser and driver versions makes a controlled environment more reproducible, but requires an update process. Selenium and ChromeDriver are software components; no specific paid physical product is required by this setup.
Or skip the browser setup
If your goal is to capture a page image or PDF rather than interact with the browser, ScreenshotNeo is a website screenshot API and MCP server. It returns PNG, JPEG, WebP, or PDF from a GET request. Its cookie handling accepts consent banners like a visitor and removes 60+ known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off.
One-call cURL example, with the API documentation for options:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Equivalent Python:
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)
Equivalent Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
const bytes = Buffer.from(await res.arrayBuffer());
require('node:fs').writeFileSync('shot.webp', bytes);
Bot checks, blank pages, failed loads, and cache hits are never billed, and response headers indicate the page verdict and billing status. The MCP server provides take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots monthly with no card; paid plans start at $5 for 3,000. Sign up for 1,000 free screenshots a month, with no card required.
FAQ
Do I need to download ChromeDriver separately?
Usually not with a current Selenium binding: if you do not provide a driver, Selenium Manager can resolve one. A manual download is still an option for custom or restricted environments.
Does ChromeDriver work with Chromium?
This guide covers Chrome and ChromeDriver. Confirm the browser and driver combination supported by your specific Chromium distribution and environment.
Can Selenium take screenshots?
Yes, Selenium can capture a screenshot of its current browser session. For a standalone URL-to-image or PDF request without managing a browser session, see the ScreenshotNeo API examples above.
When should I use Selenium Grid?
Use Grid when tests need to run across distributed machines, browsers, or operating systems. A local ChromeDriver session is simpler for one-machine automation.


