CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-seleniumhq-selenium--selenium-chromium-driver

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.

Pending
Overview
Eval results
Files

webdriver-operations.mddocs/

WebDriver Operations

The ChromiumDriver extends standard WebDriver functionality with Chromium-specific features including script pinning, authentication handling, and enhanced logging capabilities.

Core WebDriver Methods

Get Capabilities

Retrieve the current browser capabilities with Chromium-specific enhancements.

public Capabilities getCapabilities();

Returns: Capabilities - Browser capabilities including CDP and BiDi endpoints when available

Usage Example:

Capabilities caps = driver.getCapabilities();
String browserVersion = caps.getBrowserVersion();
String cdpEndpoint = (String) caps.getCapability("se:cdp");

Script Management

Script Pinning

Pin JavaScript scripts for reuse across page navigations and refreshes.

public ScriptKey pin(String script);

Parameters:

  • script (String): JavaScript code to pin for reuse

Returns: ScriptKey - Reference to the pinned script

Usage Example:

ChromiumDriver driver = new ChromiumDriver(commandExecutor, capabilities, "chrome");

// Pin a script for reuse
ScriptKey scriptKey = driver.pin("return document.title;");

// Execute the pinned script
String title = (String) driver.executeScript(scriptKey);

Get Pinned Scripts

Retrieve all currently pinned scripts.

public Set<ScriptKey> getPinnedScripts();

Returns: Set<ScriptKey> - Collection of all pinned script references

Unpin Script

Remove a pinned script from memory.

public void unpin(ScriptKey key);

Parameters:

  • key (ScriptKey): Reference to the script to unpin

Throws: JavascriptException if the script key is not found

Execute Pinned Script

Execute a previously pinned script with optional arguments.

public Object executeScript(ScriptKey key, Object... args);

Parameters:

  • key (ScriptKey): Reference to the pinned script
  • args (Object...): Arguments to pass to the script

Returns: Object - Result of script execution

Throws: JavascriptException if the script key is not found

Authentication

Register Authentication Handler

Register an authentication handler for specific URL patterns.

public void register(Predicate<URI> whenThisMatches, Supplier<Credentials> useTheseCredentials);

Parameters:

  • whenThisMatches (Predicate<URI>): Predicate to determine when to apply authentication
  • useTheseCredentials (Supplier<Credentials>): Supplier providing credentials

Usage Example:

import org.openqa.selenium.Credentials;
import java.net.URI;

driver.register(
    uri -> uri.getHost().equals("secure.example.com"),
    () -> new Credentials("username", "password")
);

Event Logging

Register Log Event Listener

Register a listener for specific log event types.

public <X> void onLogEvent(EventType<X> kind);

Parameters:

  • kind (EventType<X>): Type of log event to listen for

Usage Example:

import org.openqa.selenium.logging.EventType;

// Listen for console log events
driver.onLogEvent(EventType.CONSOLE_API);

Legacy Storage and Location APIs

Local Storage (Deprecated)

Access browser's local storage.

@Deprecated
public LocalStorage getLocalStorage();

Returns: LocalStorage - Interface to local storage operations

Session Storage (Deprecated)

Access browser's session storage.

@Deprecated  
public SessionStorage getSessionStorage();

Returns: SessionStorage - Interface to session storage operations

Location (Deprecated)

Get current geolocation.

@Deprecated
public Location location();

Returns: Location - Current geolocation

Set Location (Deprecated)

Set browser geolocation.

@Deprecated
public void setLocation(Location location);

Parameters:

  • location (Location): New geolocation to set

File Detection

Set File Detector

Note: File detection is not supported for local ChromiumDriver instances.

public void setFileDetector(FileDetector detector);

Throws: WebDriverException - Always throws as this is only supported for remote instances

Types

// Script reference for pinned scripts
public class ScriptKey {
  public String getIdentifier();
}

// Authentication credentials
public class Credentials {
  public Credentials(String username, String password);
  public String getUsername();
  public String getPassword();
}

// Event types for logging
public abstract class EventType<T> {
  public void initializeListener(WebDriver driver);
}

// Geolocation data
public class Location {
  public Location(double latitude, double longitude, double altitude);
  public double getLatitude();
  public double getLongitude(); 
  public double getAltitude();
}

Error Handling

Common exceptions that may be thrown:

  • JavascriptException: When script execution fails or script key is invalid
  • WebDriverException: For general WebDriver errors including unsupported file detection
  • IllegalArgumentException: When null or invalid parameters are provided

Best Practices

  1. Script Pinning: Use script pinning for frequently executed JavaScript to improve performance
  2. Authentication: Register authentication handlers before navigating to protected URLs
  3. Event Logging: Set up log event listeners early in the test lifecycle
  4. Resource Cleanup: Always call quit() to properly clean up pinned scripts and resources
  5. Exception Handling: Wrap script operations in try-catch blocks to handle JavaScript errors gracefully

Install with Tessl CLI

npx tessl i tessl/maven-org-seleniumhq-selenium--selenium-chromium-driver

docs

application-launching.md

browser-configuration.md

devtools-protocol.md

index.md

media-casting.md

network-conditions.md

permissions-management.md

service-management.md

webdriver-operations.md

tile.json