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 HasPermissions: Difference between revisions

From Leeroopedia
Auto-imported from implementations/SeleniumHQ_Selenium_HasPermissions.md
 
Sync from local file
 
Line 99: Line 99:


== Related Pages ==
== Related Pages ==
* [[SeleniumHQ_Selenium_HasCdp]] -- Interface for executing Chrome DevTools Protocol commands (can also manipulate permissions via CDP)
* [[Implementation:SeleniumHQ_Selenium_HasCdp]] -- Interface for executing Chrome DevTools Protocol commands (can also manipulate permissions via CDP)
* [[SeleniumHQ_Selenium_HasNetworkConditions]] -- Interface for simulating network conditions
* [[Implementation:SeleniumHQ_Selenium_HasNetworkConditions]] -- Interface for simulating network conditions
* [[SeleniumHQ_Selenium_HasCasting]] -- Interface for controlling Cast devices
* [[Implementation:SeleniumHQ_Selenium_HasCasting]] -- Interface for controlling Cast devices
* [[SeleniumHQ_Selenium_HasLaunchApp]] -- Interface for launching Chromium apps
* [[Implementation:SeleniumHQ_Selenium_HasLaunchApp]] -- Interface for launching Chromium apps
* [https://w3c.github.io/permissions/ W3C Permissions API Specification]
* [https://w3c.github.io/permissions/ W3C Permissions API Specification]
* [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

HasPermissions is a Java interface that provides the ability to programmatically set browser permissions (such as geolocation, notifications, or camera access) on Chromium-based browsers.

Description

The HasPermissions interface, annotated with @Beta, declares a single method setPermission(String name, String value) that adjusts a browser permission to a specified state. The permission name corresponds to a W3C Permissions API name (e.g., "geolocation", "notifications", "camera"), and the value is the desired permission state (e.g., "granted", "denied", "prompt"). This interface is implemented by Chromium-based driver classes such as ChromeDriver and EdgeDriver.

Usage

Use HasPermissions when testing web application behavior that depends on browser permissions, such as geolocation-based features or notification prompts. By setting permissions programmatically, you can avoid interactive permission dialogs during automated tests. Cast the driver to HasPermissions to access the setPermission method.

Code Reference

Source Location

Signature

@Beta
public interface HasPermissions {

    void setPermission(String name, String value);
}

Import

import org.openqa.selenium.chromium.HasPermissions;

I/O Contract

Methods

Method Parameters Return Type Description
setPermission(String, String) name -- the permission name to set; value -- the permission state to assign void Sets the specified browser permission to the given state.

Input

Parameter Type Description
name String The name of the permission to modify. Common values include: "geolocation", "notifications", "camera", "microphone", "clipboard-read", "clipboard-write".
value String The desired state for the permission. Valid values: "granted", "denied", "prompt".

Output

Return Type Description
void No return value. The permission is set as a side effect on the browser session.

Usage Examples

ChromeDriver driver = new ChromeDriver();

// Cast the driver to HasPermissions
HasPermissions permissionsDriver = (HasPermissions) driver;

// Grant geolocation permission to avoid the permission prompt
permissionsDriver.setPermission("geolocation", "granted");

// Deny notification permission
permissionsDriver.setPermission("notifications", "denied");

// Grant camera access
permissionsDriver.setPermission("camera", "granted");

// Grant clipboard read access
permissionsDriver.setPermission("clipboard-read", "granted");

// Reset a permission back to the prompt state
permissionsDriver.setPermission("microphone", "prompt");

// Now navigate and test features that depend on these permissions
driver.get("https://www.example.com/location-feature");

driver.quit();

Related Pages