{"record":{"id":"d4c23f524c36125e","repo":"SeleniumHQ/selenium","slug":"the-path-is-not-a-valid-file-path","errorCode":null,"errorMessage":"The path is not a valid file: {path}","messagePattern":"The path is not a valid file: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/common/driver_finder.py","lineNumber":64,"sourceCode":"    def get_browser_path(self) -> str:\n        return self._binary_paths()[\"browser_path\"]\n\n    def get_driver_path(self) -> str:\n        return self._binary_paths()[\"driver_path\"]\n\n    def _binary_paths(self) -> dict:\n        if self._paths[\"driver_path\"]:\n            return self._paths\n\n        browser = self._options.capabilities[\"browserName\"]\n        try:\n            path = self._service.path\n            if path:\n                logger.debug(\n                    \"Skipping Selenium Manager; path to %s driver specified in Service class: %s\", browser, path\n                )\n                if not Path(path).is_file():\n                    raise ValueError(f\"The path is not a valid file: {path}\")\n                self._paths[\"driver_path\"] = path\n            else:\n                output = SeleniumManager().binary_paths(self._to_args())\n                if Path(output[\"driver_path\"]).is_file():\n                    self._paths[\"driver_path\"] = output[\"driver_path\"]\n                else:\n                    raise ValueError(f\"The driver path is not a valid file: {output['driver_path']}\")\n                if Path(output[\"browser_path\"]).is_file():\n                    self._paths[\"browser_path\"] = output[\"browser_path\"]\n                else:\n                    raise ValueError(f\"The browser path is not a valid file: {output['browser_path']}\")\n        except Exception as err:\n            msg = f\"Unable to obtain driver for {browser}\"\n            raise NoSuchDriverException(msg) from err\n        return self._paths\n\n    def _to_args(self) -> list:\n        args = [\"--browser\", self._options.capabilities[\"browserName\"]]","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/common/driver_finder.py#L46-L82","documentation":"`DriverFinder._binary_paths` checks that an explicit `service.path` (a driver path the user supplied to the Service class) points to an existing regular file via `Path(path).is_file()`. If it is not a file, it raises `ValueError`, which the surrounding try/except wraps into `NoSuchDriverException` (\"Unable to obtain driver for {browser}\"). So this message is the inner cause; the user-visible exception is NoSuchDriverException.","triggerScenarios":"`Service(executable_path=\"/wrong/chromedriver\")`, `Service(\"/usr/bin\")` (a directory), `Service(\"chromedriver\")` that does not resolve to a file, or a path on a broken mount.","commonSituations":"Hardcoded driver path that is stale after an upgrade. Path correct on dev machine but missing in CI/Docker. Symlink to a driver that no longer exists. Permissions making `is_file()` return False.","solutions":["Verify the path: `pathlib.Path(p).is_file()` before constructing Service.","Omit `executable_path` and let Selenium Manager download the driver automatically.","Use an absolute path resolved from the install location.","Inspect the chained `NoSuchDriverException.__cause__` for the exact inner ValueError."],"exampleFix":"// before\nfrom selenium.webdriver.chrome.service import Service\nsvc = Service(executable_path=\"/usr/local/chromedriver\")  # not a file\n// after\nsvc = Service()  # let Selenium Manager resolve it","handlingStrategy":"validation","validationCode":"from pathlib import Path\np = \"/usr/local/chromedriver\"\nassert Path(p).is_file(), f\"driver path is not a file: {p}\"\nsvc = Service(executable_path=p)","typeGuard":"from pathlib import Path\ndef is_valid_driver_file(path) -> bool:\n    return Path(path).is_file()","tryCatchPattern":"from selenium.common.exceptions import NoSuchDriverException\ntry:\n    driver = webdriver.Chrome(service=Service(executable_path=p))\nexcept NoSuchDriverException as e:\n    print(\"cause:\", e.__cause__)\n    driver = webdriver.Chrome()  # fall back to Selenium Manager","preventionTips":["Verify Path(path).is_file() before passing executable_path.","Prefer omitting executable_path to use Selenium Manager.","Inspect NoSuchDriverException.__cause__ for the inner ValueError."],"tags":["driver-finder","service-path","filesystem","setup"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}