Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:SeleniumHQ Selenium HasCapabilities

From Leeroopedia
Revision as of 11:51, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/SeleniumHQ_Selenium_HasCapabilities.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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

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);
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment