Implementation:SeleniumHQ Selenium MutableCapabilities
| Knowledge Sources | |
|---|---|
| Domains | WebDriver, Capabilities |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for constructing and mutating browser capability maps provided by the Selenium WebDriver library.
Description
MutableCapabilities is a mutable implementation of the Capabilities interface that stores capability key-value pairs in an internal TreeMap. It provides methods to set, get, merge, and remove capabilities at runtime. The class includes special handling for browser-specific option keys (Chrome, Edge, Firefox, IE) where setting a Capabilities value for those keys causes the nested capabilities to be flattened into the parent map rather than stored as a nested object.
Usage
Import and use MutableCapabilities when you need to build up a set of browser capabilities incrementally before passing them to a WebDriver session. It serves as the base class for browser-specific options classes such as ChromeOptions, FirefoxOptions, and others.
Code Reference
Source Location
- Repository: SeleniumHQ_Selenium
- File: java/src/org/openqa/selenium/MutableCapabilities.java
Signature
public class MutableCapabilities implements Capabilities
Import
import org.openqa.selenium.MutableCapabilities;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (none) | No | No-arg constructor creates an empty capabilities map | |
| other | Capabilities |
Yes | Copy constructor; initializes from an existing Capabilities instance |
| capabilities | Map<String, ?> |
Yes | Map constructor; initializes from a string-keyed map of capability values |
| capabilityName | String |
Yes | The name of the capability to set (used by setCapability)
|
| value | Object / boolean / String / Platform |
Yes | The value of the capability to set; if null the capability is removed |
Outputs
| Name | Type | Description |
|---|---|---|
| getCapability(name) | Object (nullable) |
Returns the value for the given capability name, or null if not set |
| getCapabilityNames() | Set<String> |
Returns an unmodifiable set of all capability names currently stored |
| asMap() | Map<String, Object> |
Returns an unmodifiable view of the internal capabilities map |
| merge(other) | MutableCapabilities |
Returns a new MutableCapabilities instance merging this with the given capabilities (other overrides this) |
| toJson() | Map<String, Object> |
Returns the map representation for JSON serialization |
Usage Examples
// Create empty mutable capabilities and add entries
MutableCapabilities caps = new MutableCapabilities();
caps.setCapability("browserName", "chrome");
caps.setCapability("acceptInsecureCerts", true);
// Create from an existing map
Map<String, Object> map = new HashMap<>();
map.put("browserName", "firefox");
map.put("platformName", "LINUX");
MutableCapabilities fromMap = new MutableCapabilities(map);
// Merge two capabilities together (other overrides this)
MutableCapabilities base = new MutableCapabilities();
base.setCapability("browserName", "chrome");
MutableCapabilities extra = new MutableCapabilities();
extra.setCapability("acceptInsecureCerts", true);
MutableCapabilities merged = base.merge(extra);