Implementation:SeleniumHQ Selenium HasCdp: Difference between revisions
Auto-imported from implementations/SeleniumHQ_Selenium_HasCdp.md |
Sync from local file |
||
| Line 105: | Line 105: | ||
== Related Pages == | == Related Pages == | ||
* [[SeleniumHQ_Selenium_HasCasting]] -- Interface for controlling Cast devices from Chromium browsers | * [[Implementation:SeleniumHQ_Selenium_HasCasting]] -- Interface for controlling Cast devices from Chromium browsers | ||
* [[SeleniumHQ_Selenium_HasNetworkConditions]] -- Interface for simulating network conditions | * [[Implementation:SeleniumHQ_Selenium_HasNetworkConditions]] -- Interface for simulating network conditions | ||
* [[SeleniumHQ_Selenium_HasPermissions]] -- Interface for adjusting browser permissions | * [[Implementation:SeleniumHQ_Selenium_HasPermissions]] -- Interface for adjusting browser permissions | ||
* [[SeleniumHQ_Selenium_HasLaunchApp]] -- Interface for launching Chromium apps | * [[Implementation:SeleniumHQ_Selenium_HasLaunchApp]] -- Interface for launching Chromium apps | ||
* [https://chromedevtools.github.io/devtools-protocol/ Chrome DevTools Protocol Documentation] | * [https://chromedevtools.github.io/devtools-protocol/ Chrome DevTools Protocol Documentation] | ||
* [https://www.selenium.dev/documentation/webdriver/browsers/chrome/ Selenium Chrome Documentation] | * [https://www.selenium.dev/documentation/webdriver/browsers/chrome/ Selenium Chrome Documentation] | ||
[[Category:Implementations]] | [[Category:Implementations]] | ||
Latest revision as of 10:51, 27 September 2026
| Knowledge Sources | |
|---|---|
| Domains | WebDriver, Chromium_Browser |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
HasCdp is a Java interface that enables executing raw Chrome DevTools Protocol (CDP) commands directly through a Chromium-based WebDriver instance.
Description
The HasCdp interface, annotated with @Beta, declares a single method executeCdpCommand(String commandName, Map<String, Object> parameters) that sends an arbitrary CDP command to the browser and returns the result as a name-value map. The command name and parameters should conform to the Chrome DevTools Protocol specification. The source explicitly notes that the higher-level org.openqa.selenium.devtools.DevTools API is strongly encouraged over this low-level interface.
Usage
Use HasCdp when you need to issue CDP commands that are not yet covered by the Selenium DevTools API, or when you need direct low-level access to specific protocol domains. Cast the driver to HasCdp to access the executeCdpCommand method.
Code Reference
Source Location
- Repository: SeleniumHQ_Selenium
- File: java/src/org/openqa/selenium/chromium/HasCdp.java
Signature
@Beta
public interface HasCdp {
Map<String, Object> executeCdpCommand(String commandName, Map<String, Object> parameters);
}
Import
import org.openqa.selenium.chromium.HasCdp;
I/O Contract
Methods
| Method | Parameters | Return Type | Description |
|---|---|---|---|
executeCdpCommand(String, Map) |
commandName -- the CDP command to execute (e.g., "Network.enable"); parameters -- a map of parameter names to values required by the command |
Map<String, Object> |
Executes the specified Chrome DevTools Protocol command and returns the result as a map of response field names to their values. |
Input
| Parameter | Type | Description |
|---|---|---|
commandName |
String |
A fully qualified CDP command name following the "Domain.method" convention (e.g., "Page.navigate", "Network.emulateNetworkConditions").
|
parameters |
Map<String, Object> |
A map containing the parameters expected by the CDP command. May be an empty map if the command takes no parameters. |
Output
| Return Type | Description |
|---|---|
Map<String, Object> |
A map of response fields returned by the CDP command. The structure depends on the specific command invoked. |
Usage Examples
ChromeDriver driver = new ChromeDriver();
// Cast the driver to HasCdp
HasCdp cdpDriver = (HasCdp) driver;
// Execute a CDP command to get the browser version
Map<String, Object> version = cdpDriver.executeCdpCommand(
"Browser.getVersion", Map.of());
System.out.println("Browser: " + version.get("product"));
System.out.println("User Agent: " + version.get("userAgent"));
// Navigate using CDP directly
cdpDriver.executeCdpCommand("Page.navigate", Map.of(
"url", "https://www.selenium.dev"
));
// Enable network tracking
cdpDriver.executeCdpCommand("Network.enable", Map.of());
// Set a cookie via CDP
cdpDriver.executeCdpCommand("Network.setCookie", Map.of(
"name", "testCookie",
"value", "testValue",
"domain", "www.selenium.dev"
));
// Note: Prefer using org.openqa.selenium.devtools.DevTools API
// for type-safe, versioned CDP interaction when available.
driver.quit();
Related Pages
- Implementation:SeleniumHQ_Selenium_HasCasting -- Interface for controlling Cast devices from Chromium browsers
- Implementation:SeleniumHQ_Selenium_HasNetworkConditions -- Interface for simulating network conditions
- Implementation:SeleniumHQ_Selenium_HasPermissions -- Interface for adjusting browser permissions
- Implementation:SeleniumHQ_Selenium_HasLaunchApp -- Interface for launching Chromium apps
- Chrome DevTools Protocol Documentation
- Selenium Chrome Documentation