{"record":{"id":"81004b79b2b8eae0","repo":"crewAIInc/crewAI","slug":"driver-not-initialized-call-run-first","errorCode":null,"errorMessage":"Driver not initialized. Call _run first.","messagePattern":"Driver not initialized\\. Call _run first\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/selenium_scraping_tool/selenium_scraping_tool.py","lineNumber":166,"sourceCode":"\n    def _get_content(\n        self, css_element: str | None, return_html: bool | None\n    ) -> list[str]:\n        content: list[str] = []\n\n        if self._is_css_element_empty(css_element):\n            content.append(self._get_body_content(return_html))\n        else:\n            content.extend(self._get_elements_content(css_element, return_html))\n\n        return content\n\n    def _is_css_element_empty(self, css_element: str | None) -> bool:\n        return css_element is None or css_element.strip() == \"\"\n\n    def _get_body_content(self, return_html: bool | None) -> str:\n        if self.driver is None or self._by is None:\n            raise RuntimeError(\"Driver not initialized. Call _run first.\")\n        body_element = self.driver.find_element(self._by.TAG_NAME, \"body\")\n\n        return str(\n            body_element.get_attribute(\"outerHTML\")\n            if return_html\n            else body_element.text\n        )\n\n    def _get_elements_content(\n        self, css_element: str | None, return_html: bool | None\n    ) -> list[str]:\n        if self.driver is None or self._by is None:\n            raise RuntimeError(\"Driver not initialized. Call _run first.\")\n        elements_content: list[str] = []\n\n        for element in self.driver.find_elements(self._by.CSS_SELECTOR, css_element):\n            elements_content.append(  # noqa: PERF401\n                element.get_attribute(\"outerHTML\") if return_html else element.text","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/selenium_scraping_tool/selenium_scraping_tool.py#L148-L184","documentation":"RuntimeError raised by SeleniumScrapingTool._get_body_content when self.driver or self._by is None — i.e. the Selenium WebDriver was never initialized. The helper runs as part of content extraction after _make_request, but driver setup happens lazily in _run's __init__ path (_ensure_imports_and_driver); calling extraction before that setup, or after the driver failed to build, hits this guard. The message tells you the intended entry point is _run.","triggerScenarios":"Invoking internal helpers (_get_body_content / the content pipeline) directly on a tool whose _run never completed driver initialization; driver creation failed earlier (e.g. Chrome binary missing) leaving driver None; calling methods on a fresh instance constructed without kwargs that trigger extraction before setup.","commonSituations":"Subclassing or reusing SeleniumScrapingTool internals in custom flows; Chrome/chromedriver not installed so webdriver.Chrome() never succeeded; calling close() then continuing to use the instance.","solutions":["Enter through the public API: call tool.run(...) (i.e. _run) so the driver is initialized before extraction.","Verify Chrome and chromedriver are installed/compatible so webdriver.Chrome() actually succeeds during setup.","Do not call private helpers (_get_body_content etc.) directly; if you must, ensure a prior successful _run."],"exampleFix":"# before\ncontent = tool._get_body_content(return_html=False)  # RuntimeError\n\n# after\ncontent = tool.run(website_url=\"https://example.com\")  # _run initializes driver first","handlingStrategy":"validation","validationCode":"def driver_ready(tool) -> bool:\n    return tool.driver is not None and getattr(tool, \"_by\", None) is not None","typeGuard":null,"tryCatchPattern":"try:\n    content = tool.run(website_url=url)  # public path initializes the driver\nexcept RuntimeError as e:\n    if \"Driver not initialized\" in str(e):\n        raise RuntimeError(\"browser setup failed — check Chrome/chromedriver install\") from e\n    raise","preventionTips":["Use the public run() entry point; never call _get_body_content/_get_elements_content directly.","Verify Chrome + chromedriver exist and versions match before deploying.","Create a new tool instance after close(); do not reuse spent instances."],"tags":["lifecycle","selenium","driver-state","runtime-error"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}