From 386ecc391f5cb2248179221cd97f8f5e808209d7 Mon Sep 17 00:00:00 2001 From: Navin Chandra Date: Mon, 19 May 2025 18:11:17 +0530 Subject: [PATCH 1/3] return `message` as part of exception --- py/selenium/webdriver/remote/websocket_connection.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/py/selenium/webdriver/remote/websocket_connection.py b/py/selenium/webdriver/remote/websocket_connection.py index 34772fdb995f8..80c3341fba324 100644 --- a/py/selenium/webdriver/remote/websocket_connection.py +++ b/py/selenium/webdriver/remote/websocket_connection.py @@ -64,8 +64,10 @@ def execute(self, command): self._wait_until(lambda: current_id in self._messages) response = self._messages.pop(current_id) - if "error" in response: - raise Exception(response["error"]) + error = response["error"] + if "message" in response: + error_msg = f"{error}: {response['message']}" + raise Exception(error_msg) else: result = response["result"] return self._deserialize_result(result, command) From 6b89375f5d94f05e16b18b96acd656ee643d0f88 Mon Sep 17 00:00:00 2001 From: Navin Chandra Date: Mon, 19 May 2025 18:23:28 +0530 Subject: [PATCH 2/3] check 'error' --- py/selenium/webdriver/remote/websocket_connection.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/py/selenium/webdriver/remote/websocket_connection.py b/py/selenium/webdriver/remote/websocket_connection.py index 80c3341fba324..82f587906a21b 100644 --- a/py/selenium/webdriver/remote/websocket_connection.py +++ b/py/selenium/webdriver/remote/websocket_connection.py @@ -64,10 +64,13 @@ def execute(self, command): self._wait_until(lambda: current_id in self._messages) response = self._messages.pop(current_id) - error = response["error"] - if "message" in response: - error_msg = f"{error}: {response['message']}" - raise Exception(error_msg) + if "error" in response: + error = response["error"] + if "message" in response: + error_msg = f"{error}: {response['message']}" + raise Exception(error_msg) + else: + raise Exception(error) else: result = response["result"] return self._deserialize_result(result, command) From 0bc7e5ecdd5ebf56aeeac4b950658190935a7fdb Mon Sep 17 00:00:00 2001 From: Navin Chandra Date: Tue, 20 May 2025 07:38:28 +0530 Subject: [PATCH 3/3] raise WebDriverException --- py/selenium/webdriver/remote/websocket_connection.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/py/selenium/webdriver/remote/websocket_connection.py b/py/selenium/webdriver/remote/websocket_connection.py index 82f587906a21b..55dc83471b1a4 100644 --- a/py/selenium/webdriver/remote/websocket_connection.py +++ b/py/selenium/webdriver/remote/websocket_connection.py @@ -22,6 +22,8 @@ from websocket import WebSocketApp # type: ignore +from selenium.common import WebDriverException + logger = logging.getLogger(__name__) @@ -68,9 +70,9 @@ def execute(self, command): error = response["error"] if "message" in response: error_msg = f"{error}: {response['message']}" - raise Exception(error_msg) + raise WebDriverException(error_msg) else: - raise Exception(error) + raise WebDriverException(error) else: result = response["result"] return self._deserialize_result(result, command) @@ -102,7 +104,7 @@ def _serialize_command(self, command): def _deserialize_result(self, result, command): try: _ = command.send(result) - raise Exception("The command's generator function did not exit when expected!") + raise WebDriverException("The command's generator function did not exit when expected!") except StopIteration as exit: return exit.value