{"record":{"id":"867c60ae54c8d48d","repo":"SeleniumHQ/selenium","slug":"command-executor-must-be-a-remoteconnection-instan-867c60","errorCode":null,"errorMessage":"command_executor must be a RemoteConnection instance for BiDi support","messagePattern":"command_executor must be a RemoteConnection instance for BiDi support","errorType":"exception","errorClass":"WebDriverException","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/remote/webdriver.py","lineNumber":1228,"sourceCode":"\n    @property\n    def script(self) -> Script:\n        if not self._websocket_connection:\n            self._start_bidi()\n\n        if not self._script:\n            self._script = Script(self._websocket_connection, self)\n\n        return self._script\n\n    def _start_bidi(self) -> None:\n        if self.caps.get(\"webSocketUrl\"):\n            ws_url = self.caps.get(\"webSocketUrl\")\n        else:\n            raise WebDriverException(\"Unable to find url to connect to from capabilities\")\n\n        if not isinstance(self.command_executor, RemoteConnection):\n            raise WebDriverException(\"command_executor must be a RemoteConnection instance for BiDi support\")\n\n        self._websocket_connection = WebSocketConnection(\n            ws_url,\n            self.command_executor.client_config.websocket_timeout,\n            self.command_executor.client_config.websocket_interval,\n        )\n\n    @property\n    def network(self) -> Network:\n        if not self._websocket_connection:\n            self._start_bidi()\n\n        assert self._websocket_connection is not None\n        if not hasattr(self, \"_network\") or self._network is None:\n            assert self._websocket_connection is not None\n            self._network = Network(self._websocket_connection)\n\n        return self._network","sourceCodeStart":1210,"sourceCodeEnd":1246,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/remote/webdriver.py#L1210-L1246","documentation":"Raised by _start_bidi() when self.command_executor is not a RemoteConnection instance. The BiDi startup reads client_config.websocket_timeout and websocket_interval from the executor to construct the WebSocketConnection; a non-RemoteConnection executor lacks this attribute. This is the BiDi analogue of the CDP executor-type guard.","triggerScenarios":"Building a driver with a custom/mock command_executor that is not a RemoteConnection, then accessing driver.script or driver.network (which lazily call _start_bidi).","commonSituations":"Test harnesses injecting a fake executor, custom WebDriver subclasses, or third-party transports that do not extend RemoteConnection.","solutions":["Use RemoteConnection (or a subclass exposing client_config) as the command_executor.","If you subclass the executor, inherit from RemoteConnection so isinstance holds.","Avoid BiDi features when running against a non-standard executor."],"exampleFix":"# before\ndriver = webdriver.Remote(command_executor=FakeExecutor(...))\ndriver.script  # raises\n\n# after\nfrom selenium.webdriver.remote.remote_connection import RemoteConnection\ndriver = webdriver.Remote(command_executor=RemoteConnection(url, websocket_timeout=60))","handlingStrategy":"type-guard","validationCode":"from selenium.webdriver.remote.remote_connection import RemoteConnection\nif not isinstance(driver.command_executor, RemoteConnection):\n    raise TypeError('BiDi requires a RemoteConnection executor')\ndriver.script","typeGuard":"from selenium.webdriver.remote.remote_connection import RemoteConnection\ndef has_remote_connection(driver) -> bool:\n    return isinstance(driver.command_executor, RemoteConnection)","tryCatchPattern":"from selenium.common.exceptions import WebDriverException\ntry:\n    driver.script\nexcept WebDriverException as e:\n    if 'RemoteConnection' in str(e):\n        raise","preventionTips":["Use a RemoteConnection (or subclass) as command_executor.","Subclass RemoteConnection for custom transports.","Avoid non-RemoteConnection executors when using BiDi."],"tags":["bidi","remote-connection","executor","type-checking"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}