Implementation:SeleniumHQ Selenium HasCapabilities
| Knowledge Sources | |
|---|---|
| Domains | WebDriver, Capabilities |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for enabling run-time capability introspection on WebDriver instances provided by the Selenium WebDriver library.
Description
HasCapabilities is a marker interface that classes implement to indicate they can describe the Capabilities they possess. It defines a single method, getCapabilities(), which returns the capabilities of the current driver. This enables run-time feature detection by allowing callers to inspect what a driver supports without relying on compile-time type checks.
Usage
Import and use HasCapabilities when you need to check the capabilities of a running WebDriver instance at runtime, for example to determine the browser name, platform, or whether specific features are enabled. Cast a WebDriver to HasCapabilities to access the getCapabilities() method.
Code Reference
Source Location
- Repository: SeleniumHQ_Selenium
- File: java/src/org/openqa/selenium/HasCapabilities.java
Signature
public interface HasCapabilities {
Capabilities getCapabilities();
}
Import
import org.openqa.selenium.HasCapabilities;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (none) | This interface has no input parameters; it is implemented by driver classes |
Outputs
| Name | Type | Description |
|---|---|---|
| getCapabilities() | Capabilities |
Returns the capabilities of the current driver instance |
Usage Examples
WebDriver driver = new ChromeDriver();
// Cast to HasCapabilities to inspect driver capabilities at runtime
if (driver instanceof HasCapabilities) {
Capabilities caps = ((HasCapabilities) driver).getCapabilities();
String browserName = caps.getBrowserName();
System.out.println("Running on: " + browserName);
// Check for specific capability
Object platformName = caps.getCapability("platformName");
System.out.println("Platform: " + platformName);
}