Can we enable execute_cdp for driver instance from webdriver.Remote()?
currently we are getting an Attribute Error for the following
Requiremnts
Python 3.6.9
selenium 3.141.0
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--no-sandbox")
driver = webdriver.Remote(
command_executor='https://remote/webdriver',
desired_capabilities=chrome_options.to_capabilities()
)
driver.execute_cdp_cmd("execute something")
AttributeError: 'WebDriver' object has no attribute 'execute_cdp_cmd'
Already execute_cdp_cmd is availbe for selenium.webdriver.chrome.webdriver
https://www.selenium.dev/selenium/docs/api/py/webdriver_chrome/selenium.webdriver.chrome.webdriver.html#selenium.webdriver.chrome.webdriver.WebDriver.execute_cdp_cmd
driver.execute_cdp_cmd("execute something")
A workaround would be using this function:
import json
def send(driver, cmd, params={}):
resource = "/session/%s/chromium/send_command_and_get_result" % driver.session_id
url = driver.command_executor._url + resource
body = json.dumps({'cmd': cmd, 'params': params})
response = driver.command_executor._request('POST', url, body)
return response.get('value')
If you use pip install --pre selenium you should get the ability to execute CDP commands.
It's in the code base with this line: https://github.com/SeleniumHQ/selenium/blob/trunk/py/selenium/webdriver/remote/webdriver.py#L117
Closing this as the new mechanisms for using CDP are available to remote. We won't be adding this command as it was a workaround by the Chrome team
Most helpful comment
A workaround would be using this function:
source: https://stackoverflow.com/a/47298910/8524395