{"record":{"id":"358cb24df327308a","repo":"SeleniumHQ/selenium","slug":"cdp-module-not-loaded","errorCode":null,"errorMessage":"CDP module not loaded","messagePattern":"CDP module not loaded","errorType":"exception","errorClass":"WebDriverException","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/remote/webdriver.py","lineNumber":1160,"sourceCode":"            raise WebDriverException(\"You can only set the orientation to 'LANDSCAPE' and 'PORTRAIT'\")\n\n    def start_devtools(self) -> tuple[Any, WebSocketConnection]:\n        global cdp\n        import_cdp()\n        if self.caps.get(\"se:cdp\"):\n            ws_url = self.caps.get(\"se:cdp\")\n            cdp_version = self.caps.get(\"se:cdpVersion\")\n            if cdp_version is None:\n                raise WebDriverException(\"CDP version not found in capabilities\")\n            version = cdp_version.split(\".\")[0]\n        else:\n            version, ws_url = self._get_cdp_details()\n\n        if not ws_url:\n            raise WebDriverException(\"Unable to find url to connect to from capabilities\")\n\n        if cdp is None:\n            raise WebDriverException(\"CDP module not loaded\")\n\n        self._devtools = cdp.import_devtools(version)\n        if self._websocket_connection:\n            return self._devtools, self._websocket_connection\n        if self.caps[\"browserName\"].lower() == \"firefox\":\n            raise RuntimeError(\"CDP support for Firefox has been removed. Please switch to WebDriver BiDi.\")\n        if not isinstance(self.command_executor, RemoteConnection):\n            raise WebDriverException(\"command_executor must be a RemoteConnection instance for CDP support\")\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        targets = self._websocket_connection.execute(self._devtools.target.get_targets())\n        for target in targets:\n            if target.target_id == self.current_window_handle:\n                target_id = target.target_id\n                break","sourceCodeStart":1142,"sourceCodeEnd":1178,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/remote/webdriver.py#L1142-L1178","documentation":"Raised by start_devtools() when the global cdp module is still None after import_cdp() was called. The CDP bindings are an optional dependency shipped as a separate module; if importing them failed silently or they are absent, Selenium cannot translate DevTools commands. This guard prevents a confusing AttributeError later.","triggerScenarios":"The bundled CDP module failed to import (missing dependencies, corrupted install, partial Selenium installation) so import_cdp() did not populate the global cdp. Then start_devtools() proceeds past the URL checks and hits this guard.","commonSituations":"A broken or partial Selenium install (e.g. manually deleted the cdp subpackage), an environment where the CDP module's transitive dependencies are missing, or a custom packaging that excludes the devtools bindings.","solutions":["Reinstall Selenium cleanly: pip install --force-reinstall selenium.","Verify the import works in isolation: python -c 'from selenium.webdriver.common.bidi import import_cdp; import_cdp(); from selenium.webdriver import remote; print(remote.cdp)'.","Check for conflicting selenium installs on sys.path (pip show selenium, and look for multiple installs)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"# Verify CDP import works before using it\nfrom selenium.webdriver.common.bidi import import_cdp\nimport_cdp()\nfrom selenium.webdriver.remote import webdriver as _w\nif _w.cdp is None:\n    raise RuntimeError('CDP module failed to import; reinstall selenium')","typeGuard":null,"tryCatchPattern":"from selenium.common.exceptions import WebDriverException\ntry:\n    devtools, conn = driver.start_devtools()\nexcept WebDriverException as e:\n    if 'CDP module not loaded' in str(e):\n        import subprocess; subprocess.run(['pip', 'install', '--force-reinstall', 'selenium'])","preventionTips":["Install Selenium from a clean source (pip).","Check for duplicate/partial selenium installs on sys.path.","Smoke-test the CDP import in CI for environments that use DevTools."],"tags":["cdp","devtools","import","installation"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}