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_callback

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Parse the exception text to extract the BiDi error code before the colon and map it to spec handling.
  2. Validate command parameters (context id, script, etc.) before sending.
  3. Ensure the browser/driver version supports the BiDi command you call.
  4. 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

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


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/2fe567aa1e18e563. Report an issue: GitHub.