Selenium Chrome Driver provides WebDriver implementation for Google Chrome with Chrome DevTools Protocol support, network conditions simulation, permissions management, media casting capabilities, and Chrome-specific service configuration.
—
ChromeDriverService provides comprehensive lifecycle management for the ChromeDriver executable, including configuration options for logging, security, and build compatibility.
Create a ChromeDriverService with default configuration.
public static ChromeDriverService createDefaultService();Returns: ChromeDriverService - Service instance configured with default settings
Usage Example:
import org.openqa.selenium.chrome.ChromeDriverService;
// Create default service
ChromeDriverService service = ChromeDriverService.createDefaultService();
// Use with driver
ChromeDriver driver = new ChromeDriver(service);Use the Builder pattern for advanced service configuration.
public static class Builder extends DriverService.Builder<ChromeDriverService, ChromeDriverService.Builder> {
public Builder withAppendLog(boolean appendLog);
public Builder withBuildCheckDisabled(boolean noBuildCheck);
public Builder withLogLevel(ChromiumDriverLogLevel logLevel);
public Builder withSilent(boolean silent);
public Builder withVerbose(boolean verbose);
public Builder withAllowedListIps(String allowedListIps);
public Builder withReadableTimestamp(Boolean readableTimestamp);
public int score(Capabilities capabilities);
}Usage Example:
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chromium.ChromiumDriverLogLevel;
import java.io.File;
ChromeDriverService service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File("/path/to/chromedriver"))
.usingAnyFreePort()
.withLogLevel(ChromiumDriverLogLevel.INFO)
.withVerbose(false)
.withAppendLog(true)
.withLogFile(new File("/tmp/chromedriver.log"))
.build();ChromeDriverService supports various system properties for configuration:
public static final String CHROME_DRIVER_NAME = "chromedriver";
public static final String CHROME_DRIVER_EXE_PROPERTY = "webdriver.chrome.driver";
public static final String CHROME_DRIVER_LOG_PROPERTY = "webdriver.chrome.logfile";
public static final String CHROME_DRIVER_LOG_LEVEL_PROPERTY = "webdriver.chrome.loglevel";
public static final String CHROME_DRIVER_VERBOSE_LOG_PROPERTY = "webdriver.chrome.verboseLogging";
public static final String CHROME_DRIVER_SILENT_OUTPUT_PROPERTY = "webdriver.chrome.silentOutput";
public static final String CHROME_DRIVER_APPEND_LOG_PROPERTY = "webdriver.chrome.appendLog";
public static final String CHROME_DRIVER_ALLOWED_IPS_PROPERTY = "webdriver.chrome.withAllowedIps";
public static final String CHROME_DRIVER_DISABLE_BUILD_CHECK = "webdriver.chrome.disableBuildCheck";
public static final String CHROME_DRIVER_READABLE_TIMESTAMP = "webdriver.chrome.readableTimestamp";System Property Usage:
// Set system properties before creating service
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
System.setProperty("webdriver.chrome.logfile", "/tmp/chromedriver.log");
System.setProperty("webdriver.chrome.loglevel", "INFO");
ChromeDriverService service = ChromeDriverService.createDefaultService();Set the logging level for ChromeDriver output.
public Builder withLogLevel(ChromiumDriverLogLevel logLevel);Parameters:
logLevel (ChromiumDriverLogLevel): Desired log level (ALL, INFO, DEBUG, WARNING, SEVERE, OFF)Returns: Builder - Builder instance for method chaining
Usage Example:
import org.openqa.selenium.chromium.ChromiumDriverLogLevel;
ChromeDriverService service = new ChromeDriverService.Builder()
.withLogLevel(ChromiumDriverLogLevel.DEBUG)
.build();Enable verbose logging for detailed output.
public Builder withVerbose(boolean verbose);Parameters:
verbose (boolean): Enable verbose logging if trueReturns: Builder - Builder instance for method chaining
Configure the service to run in silent mode with minimal output.
public Builder withSilent(boolean silent);Parameters:
silent (boolean): Enable silent mode if trueReturns: Builder - Builder instance for method chaining
Configure log file appending behavior.
public Builder withAppendLog(boolean appendLog);Parameters:
appendLog (boolean): Append to existing log file if true, overwrite if falseReturns: Builder - Builder instance for method chaining
Configure timestamp formatting in log output.
public Builder withReadableTimestamp(Boolean readableTimestamp);Parameters:
readableTimestamp (Boolean): Use human-readable timestamps if trueReturns: Builder - Builder instance for method chaining
Configure which IP addresses are allowed to connect to the ChromeDriver service.
public Builder withAllowedListIps(String allowedListIps);Parameters:
allowedListIps (String): Comma-separated list of allowed IPv4 addressesReturns: Builder - Builder instance for method chaining
Usage Example:
ChromeDriverService service = new ChromeDriverService.Builder()
.withAllowedListIps("127.0.0.1,192.168.1.100")
.build();Disable version compatibility checking between ChromeDriver and Chrome browser.
public Builder withBuildCheckDisabled(boolean noBuildCheck);Parameters:
noBuildCheck (boolean): Disable build compatibility check if trueReturns: Builder - Builder instance for method chaining
Usage Example:
ChromeDriverService service = new ChromeDriverService.Builder()
.withBuildCheckDisabled(true) // Allow potentially incompatible versions
.build();Get the name of the driver executable.
public String getDriverName();Returns: String - Driver executable name ("chromedriver")
Get the system property name for the driver executable path.
public String getDriverProperty();Returns: String - System property name ("webdriver.chrome.driver")
Get the default capabilities for this driver service.
public Capabilities getDefaultDriverOptions();Returns: Capabilities - Default ChromeOptions instance
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chromium.ChromiumDriverLogLevel;
import java.io.File;
import java.time.Duration;
// Configure comprehensive service
ChromeDriverService service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File("/path/to/chromedriver"))
.usingPort(9515)
.withTimeout(Duration.ofSeconds(30))
.withLogFile(new File("/tmp/chromedriver.log"))
.withLogLevel(ChromiumDriverLogLevel.INFO)
.withAppendLog(true)
.withReadableTimestamp(true)
.withAllowedListIps("127.0.0.1,10.0.0.0/8")
.withBuildCheckDisabled(false)
.build();
// Use configured service
ChromeOptions options = new ChromeOptions();
ChromeDriver driver = new ChromeDriver(service, options);
// Ensure cleanup
try {
driver.get("https://example.com");
// Test operations...
} finally {
driver.quit();
}Service-related exceptions that may occur:
WebDriverException - General service startup/shutdown issuesIOException - File system problems with logs or executableIllegalArgumentException - Invalid configuration parametersIllegalStateException - Service already started/stoppedCommon troubleshooting:
Install with Tessl CLI
npx tessl i tessl/maven-org-seleniumhq-selenium--selenium-chromium-driver