MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / ErrorHandler

Class ErrorHandler

py/selenium/webdriver/remote/errorhandler.py:142–232  ·  view source on GitHub ↗

Handles errors returned by the WebDriver server.

Source from the content-addressed store, hash-verified

140
141
142class ErrorHandler:
143 """Handles errors returned by the WebDriver server."""
144
145 def check_response(self, response: dict[str, Any]) -> None:
146 """Check that a JSON response from the WebDriver does not have an error.
147
148 Args:
149 response: The JSON response from the WebDriver server as a dictionary
150 object.
151
152 Raises:
153 WebDriverException: If the response contains an error message.
154 """
155 status = response.get("status", None)
156 if not status or status == ErrorCode.SUCCESS:
157 return
158 value = None
159 message = response.get("message", "")
160 screen: str = response.get("screen", "")
161 stacktrace = None
162 if isinstance(status, int):
163 value_json = response.get("value", None)
164 if value_json and isinstance(value_json, str):
165 try:
166 value = json.loads(value_json)
167 if isinstance(value, dict):
168 if len(value) == 1:
169 value = value["value"]
170 status = value.get("error", None)
171 if not status:
172 status = value.get("status", ErrorCode.UNKNOWN_ERROR)
173 message = value.get("value") or value.get("message")
174 if not isinstance(message, str):
175 value = message
176 message = message.get("message") if isinstance(message, dict) else None
177 else:
178 message = value.get("message", None)
179 except ValueError:
180 pass
181
182 exception_class: type[WebDriverException]
183 e = ErrorCode()
184 error_codes = [item for item in dir(e) if not item.startswith("__")]
185 for error_code in error_codes:
186 error_info = getattr(ErrorCode, error_code)
187 if isinstance(error_info, list) and status in error_info:
188 exception_class = getattr(ExceptionMapping, error_code, WebDriverException)
189 break
190 else:
191 exception_class = WebDriverException
192
193 if not value:
194 value = response["value"]
195 if isinstance(value, str):
196 raise exception_class(value)
197 if message == "" and "message" in value:
198 message = value["message"]
199

Callers 2

__init__Method · 0.90
handlerFunction · 0.90

Calls

no outgoing calls

Tested by 1

handlerFunction · 0.72