SeleniumHQ/selenium · error · WebDriverException
{error}: {response['message']}
Error message
{error}: {response['message']} What it means
The remote BiDi end returned an error response object carrying both an `error` field (the BiDi-spec error type) and a `message` field (human-readable detail). The library formats them as '{error}: {message}' and re-raises as WebDriverException.
Source
Thrown at py/selenium/webdriver/remote/websocket_connection.py:140
payload = self._serialize_command(command)
payload["id"] = current_id
if self.session_id:
payload["sessionId"] = self.session_id
data = json.dumps(payload, cls=_BiDiEncoder)
logger.debug(f"-> {data}"[: self._max_log_message_size])
self._ws.send(data)
self._wait_until(lambda: current_id in self._messages)
if current_id not in self._messages:
raise WebDriverException(f"Timed out waiting for response to BiDi command {current_id}")
response = self._messages.pop(current_id)
if "error" in response:
error = response["error"]
if "message" in response:
error_msg = f"{error}: {response['message']}"
raise WebDriverException(error_msg)
else:
raise WebDriverException(error)
else:
result = response["result"]
return self._deserialize_result(result, command)
def add_callback(self, event, callback):
event_name = event.event_class
if event_name not in self.callbacks:
self.callbacks[event_name] = []
def _callback(params):
callback(event.from_json(params))
self.callbacks[event_name].append(_callback)
return id(_callback)
on = add_callbackView on GitHub (pinned to aa36b38e69)
Solutions
- Parse the exception text to extract the BiDi error code before the colon and map it to spec handling.
- Validate command parameters (context id, script, etc.) before sending.
- Ensure the browser/driver version supports the BiDi command you call.
- Re-open the browsing context / session if it was closed.
Example fix
# before
conn.execute(BrowsingContext.Navigate(context=closed_id, url=u))
# after
if context_still_open(closed_id):
conn.execute(BrowsingContext.Navigate(context=closed_id, url=u)) Defensive patterns
Strategy: try-catch
Try / catch
try:
result = conn.execute(cmd)
except WebDriverException as e:
code, _, detail = str(e).partition(": ")
if code == "no such browsing context":
reopen_and_retry()
else:
raise Prevention
- Inspect the error code portion to branch on known BiDi error types.
- Do not reuse context handles across navigations that reset the session.
When it happens
Trigger: Sending a malformed BiDi command (invalid params), referencing an unknown or already-closed browsing context, an unknown command, or any protocol-level error such as 'invalid argument' / 'no such frame'.
Common situations: Using a browsing context handle after it was closed, passing wrong parameter types to a BiDi command, or version skew between the client's command set and the browser's BiDi support.
Related errors
- Unknown error: ${JSON.stringify(data)}
- ${message}
- #{message['error']}: #{message['message']} #{message['stackt
- Pattern must be an instance of UrlPattern. Received: '${patt
- Pattern must be an instance of UrlPattern. Received:'${patte
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/2fe567aa1e18e563.
Report an issue: GitHub.