Implementation:SeleniumHQ Selenium ChromeDriver Constructor
| Knowledge Sources | |
|---|---|
| Domains | Browser_Automation, WebDriver, Session_Management |
| Last Updated | 2026-02-11 00:00 GMT |
Overview
Concrete tool for creating a Chrome WebDriver session provided by the Selenium Java library.
Description
The ChromeDriver constructor orchestrates the complete session creation workflow: it resolves the chromedriver binary via DriverFinder (which uses SeleniumManager), starts a ChromeDriverService, establishes an HTTP command executor via ChromiumDriverCommandExecutor, and initiates a W3C session via POST /session. ChromeDriver extends ChromiumDriver which extends RemoteWebDriver, inheriting the full W3C WebDriver command set. The constructor also registers CDP (Chrome DevTools Protocol) capabilities via AddHasCdp and Casting capabilities via AddHasCasting. The generateExecutor private static method handles the driver finder integration, setting the resolved executable and browser binary path on the service and options respectively.
Usage
Use this constructor to start a new Chrome browser automation session. The most common overloads are the no-arg constructor (uses defaults) and the single-arg ChromeOptions constructor (for customized sessions).
Code Reference
Source Location
- Repository: Selenium
- File: java/src/org/openqa/selenium/chrome/ChromeDriver.java
- Lines: L42-132
- Parent: java/src/org/openqa/selenium/chromium/ChromiumDriver.java (L73-423)
Signature
public class ChromeDriver extends ChromiumDriver {
public ChromeDriver();
public ChromeDriver(ChromeDriverService service);
public ChromeDriver(ChromeOptions options);
public ChromeDriver(ChromeOptions options, ClientConfig clientConfig);
public ChromeDriver(ChromeDriverService service, ChromeOptions options);
public ChromeDriver(ChromeDriverService service, ChromeOptions options,
ClientConfig clientConfig);
@Beta
public static RemoteWebDriverBuilder builder();
}
Import
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.remote.http.ClientConfig;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| service | ChromeDriverService | No | Pre-configured driver service (created via createDefaultService() if omitted) |
| options | ChromeOptions | No | Browser capabilities (new ChromeOptions() defaults used if omitted) |
| clientConfig | ClientConfig | No | HTTP client configuration for command executor (ClientConfig.defaultConfig() if omitted) |
Outputs
| Name | Type | Description |
|---|---|---|
| driver | ChromeDriver | Active WebDriver session with valid sessionId, connected to Chrome browser |
| getSessionId() | SessionId | Unique identifier for this session |
| getCapabilities() | Capabilities | Matched capabilities from the server, enriched with se:cdp and se:cdpVersion if CDP is available |
Usage Examples
Default Chrome Session
import org.openqa.selenium.chrome.ChromeDriver;
// Creates default service, default options, starts Chrome
ChromeDriver driver = new ChromeDriver();
driver.get("https://www.selenium.dev");
System.out.println(driver.getTitle());
driver.quit();
Chrome with Options
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless", "--window-size=1920,1080");
ChromeDriver driver = new ChromeDriver(options);
driver.get("https://example.com");
driver.quit();
Chrome with Service and Options
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chrome.ChromeDriverService;
ChromeDriverService service = new ChromeDriverService.Builder()
.usingPort(9515)
.build();
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
ChromeDriver driver = new ChromeDriver(service, options);
driver.get("https://example.com");
driver.quit(); // also stops the service
Using the Builder Pattern
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.RemoteWebDriverBuilder;
// Beta builder API
RemoteWebDriverBuilder builder = ChromeDriver.builder();
WebDriver driver = builder.build();