From 4bb53533fdec489f3db8551c1f96fe65d58eca05 Mon Sep 17 00:00:00 2001 From: Swastik Baranwal Date: Mon, 9 Dec 2024 10:56:55 +0530 Subject: [PATCH] [py] add execute_cdp_cmd to Remote (#14809) * [py] add execute_cdp_cmd to Remote * use inherited method --- py/selenium/webdriver/chromium/webdriver.py | 2 +- py/selenium/webdriver/remote/webdriver.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/py/selenium/webdriver/chromium/webdriver.py b/py/selenium/webdriver/chromium/webdriver.py index af563f41672a8..93124c68a0d0c 100644 --- a/py/selenium/webdriver/chromium/webdriver.py +++ b/py/selenium/webdriver/chromium/webdriver.py @@ -138,7 +138,7 @@ def execute_cdp_cmd(self, cmd: str, cmd_args: dict): For example to getResponseBody: {'base64Encoded': False, 'body': 'response body string'} """ - return self.execute("executeCdpCommand", {"cmd": cmd, "params": cmd_args})["value"] + return super().execute_cdp_cmd(cmd, cmd_args) def get_sinks(self) -> list: """:Returns: A list of sinks available for Cast.""" diff --git a/py/selenium/webdriver/remote/webdriver.py b/py/selenium/webdriver/remote/webdriver.py index 27e6114e06d99..564fb465369df 100644 --- a/py/selenium/webdriver/remote/webdriver.py +++ b/py/selenium/webdriver/remote/webdriver.py @@ -361,6 +361,26 @@ def _unwrap_value(self, value): return list(self._unwrap_value(item) for item in value) return value + def execute_cdp_cmd(self, cmd: str, cmd_args: dict): + """Execute Chrome Devtools Protocol command and get returned result The + command and command args should follow chrome devtools protocol + domains/commands, refer to link + https://chromedevtools.github.io/devtools-protocol/ + + :Args: + - cmd: A str, command name + - cmd_args: A dict, command args. empty dict {} if there is no command args + :Usage: + :: + + driver.execute_cdp_cmd('Network.getResponseBody', {'requestId': requestId}) + :Returns: + A dict, empty dict {} if there is no result to return. + For example to getResponseBody: + {'base64Encoded': False, 'body': 'response body string'} + """ + return self.execute("executeCdpCommand", {"cmd": cmd, "params": cmd_args})["value"] + def execute(self, driver_command: str, params: dict = None) -> dict: """Sends a command to be executed by a command.CommandExecutor.