Selenium Chrome WebDriver implementation for automating Chrome browsers using the WebDriver protocol
—
Core Chrome WebDriver functionality providing browser automation, navigation, element interaction, session management, and Chrome-specific features like app launching and geolocation.
Main WebDriver implementation that controls Chrome browser instances with support for local storage, geolocation, touch interactions, and network connection management.
/**
* A WebDriver implementation that controls a Chrome browser running on the local machine.
* Extends RemoteWebDriver with Chrome-specific functionality.
*/
public class ChromeDriver extends RemoteWebDriver
implements LocationContext, WebStorage, HasTouchScreen, NetworkConnection {
/**
* Creates a new ChromeDriver using the default server configuration.
*/
public ChromeDriver();
/**
* Creates a new ChromeDriver instance. The service will be started along with the driver,
* and shutdown upon calling quit().
* @param service The service to use
*/
public ChromeDriver(ChromeDriverService service);
/**
* Creates a new ChromeDriver instance with the specified options.
* @param options The options to use
*/
public ChromeDriver(ChromeOptions options);
/**
* Creates a new ChromeDriver instance with the specified options. The service will be
* started along with the driver, and shutdown upon calling quit().
* @param service The service to use
* @param options The options to use
*/
public ChromeDriver(ChromeDriverService service, ChromeOptions options);
/**
* Creates a new ChromeDriver instance with capabilities (deprecated).
* @param capabilities The capabilities required from the ChromeDriver
* @deprecated Use ChromeDriver(ChromeOptions) instead
*/
@Deprecated
public ChromeDriver(Capabilities capabilities);
/**
* Creates a new ChromeDriver instance with service and capabilities (deprecated).
* @param service The service to use
* @param capabilities The capabilities required from the ChromeDriver
* @deprecated Use ChromeDriver(ChromeDriverService, ChromeOptions) instead
*/
@Deprecated
public ChromeDriver(ChromeDriverService service, Capabilities capabilities);
}Usage Examples:
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.WebDriver;
// Basic usage with default configuration
WebDriver driver = new ChromeDriver();
// With custom options
ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
WebDriver driver = new ChromeDriver(options);
// With custom service
ChromeDriverService service = ChromeDriverService.createDefaultService();
WebDriver driver = new ChromeDriver(service);
// Full configuration
ChromeDriverService service = new ChromeDriverService.Builder()
.usingAnyFreePort()
.withVerbose(true)
.build();
ChromeOptions options = new ChromeOptions();
options.addArguments("--no-sandbox");
WebDriver driver = new ChromeDriver(service, options);Chrome-specific file detection handling for remote WebDriver scenarios.
/**
* Throws WebDriverException as file detection is not supported for local ChromeDriver.
* @param detector The file detector to set
* @throws WebDriverException Always thrown for local ChromeDriver instances
*/
public void setFileDetector(FileDetector detector);HTML5 local storage interface for persisting data in the browser.
/**
* Gets the local storage interface for the current session.
* @return LocalStorage interface for storing key-value pairs
*/
public LocalStorage getLocalStorage();HTML5 session storage interface for temporary data storage.
/**
* Gets the session storage interface for the current session.
* @return SessionStorage interface for storing temporary key-value pairs
*/
public SessionStorage getSessionStorage();Geolocation API for getting and setting browser location coordinates.
/**
* Gets the current geolocation of the browser.
* @return Current Location with latitude, longitude, and altitude
*/
public Location location();
/**
* Sets the geolocation of the browser.
* @param location The location to set with coordinates
*/
public void setLocation(Location location);Usage Example:
import org.openqa.selenium.html5.Location;
// Get current location
Location currentLocation = ((ChromeDriver) driver).location();
System.out.println("Lat: " + currentLocation.getLatitude());
System.out.println("Lng: " + currentLocation.getLongitude());
// Set new location
Location newLocation = new Location(37.7749, -122.4194, 0); // San Francisco
((ChromeDriver) driver).setLocation(newLocation);Touch screen interaction support for mobile testing scenarios.
/**
* Gets the touch screen interface for performing touch interactions.
* @return TouchScreen interface for touch gestures and interactions
*/
public TouchScreen getTouch();Network connection type management for simulating different network conditions.
/**
* Gets the current network connection type.
* @return Current ConnectionType (WIFI, CELL_4G, etc.)
*/
public ConnectionType getNetworkConnection();
/**
* Sets the network connection type for testing different network scenarios.
* @param type The connection type to simulate
* @return The connection type that was set
*/
public ConnectionType setNetworkConnection(ConnectionType type);Chrome-specific functionality for launching Chrome apps by application ID.
/**
* Launches Chrome app specified by id.
* @param id Chrome app id to launch
*/
public void launchApp(String id);Usage Example:
// Launch a Chrome app
ChromeDriver chromeDriver = (ChromeDriver) driver;
chromeDriver.launchApp("app_id_here");// Connection types for network simulation
enum ConnectionType {
NONE, AIRPLANE, WIFI, CELL_2G, CELL_3G, CELL_4G
}
// Location for geolocation API
class Location {
public Location(double latitude, double longitude, double altitude);
public double getLatitude();
public double getLongitude();
public double getAltitude();
}
// Storage interfaces
interface LocalStorage {
void setItem(String key, String value);
String getItem(String key);
void removeItem(String key);
void clear();
Set<String> keySet();
}
interface SessionStorage {
void setItem(String key, String value);
String getItem(String key);
void removeItem(String key);
void clear();
Set<String> keySet();
}
// Touch interface
interface TouchScreen {
void singleTap(Coordinates where);
void down(int x, int y);
void up(int x, int y);
void move(int x, int y);
void scroll(Coordinates where, int xOffset, int yOffset);
void doubleTap(Coordinates where);
void longPress(Coordinates where);
}Install with Tessl CLI
npx tessl i tessl/maven-org-seleniumhq-selenium--selenium-chrome-driver