SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.86k stars 8.22k forks source link

[🚀 Feature]: Expose Chromium commands API in Remote #14799

Open p0deje opened 6 days ago

p0deje commented 6 days ago

Feature and motivation

Currently there is a number of custom methods that expose Chromium commands in Chromium driver:

from selenium.webdriver import Chrome

driver = Chrome()
driver.execute_cdp_cmd('Page.enable')                                     # <-- custom method that calls command below
driver.execute("executeCdpCommand", {"cmd": "Page.enable', "params": {}}) # <-- custom command execution

The same commands should be accessible via Remote driver as well since Grid provides the endpoints and the underlying command executor actually already supports the commands:

from selenium.webdriver.chrome.options import Options
from selenium.webdriver import Remote

driver = Remote(options=Options())
driver.execute_cdp_cmd('Page.enable')                                     # <-- this method is not available
driver.execute("executeCdpCommand", {"cmd": "Page.enable', "params": {}}) # <-- this still works!

The same approach is implemented in other bindings (Java, Ruby), where instances of Remote driver are augmented to support custom methods and commands specific to browsers.

Usage example

See above for usage example.

Delta456 commented 5 days ago

I will try to work on this.