SeleniumHQ/selenium · error · ValueError
The path is not a valid file: {path}
Error message
The path is not a valid file: {path} What it means
`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.
Source
Thrown at py/selenium/webdriver/common/driver_finder.py:64
def get_browser_path(self) -> str:
return self._binary_paths()["browser_path"]
def get_driver_path(self) -> str:
return self._binary_paths()["driver_path"]
def _binary_paths(self) -> dict:
if self._paths["driver_path"]:
return self._paths
browser = self._options.capabilities["browserName"]
try:
path = self._service.path
if path:
logger.debug(
"Skipping Selenium Manager; path to %s driver specified in Service class: %s", browser, path
)
if not Path(path).is_file():
raise ValueError(f"The path is not a valid file: {path}")
self._paths["driver_path"] = path
else:
output = SeleniumManager().binary_paths(self._to_args())
if Path(output["driver_path"]).is_file():
self._paths["driver_path"] = output["driver_path"]
else:
raise ValueError(f"The driver path is not a valid file: {output['driver_path']}")
if Path(output["browser_path"]).is_file():
self._paths["browser_path"] = output["browser_path"]
else:
raise ValueError(f"The browser path is not a valid file: {output['browser_path']}")
except Exception as err:
msg = f"Unable to obtain driver for {browser}"
raise NoSuchDriverException(msg) from err
return self._paths
def _to_args(self) -> list:
args = ["--browser", self._options.capabilities["browserName"]]View on GitHub (pinned to aa36b38e69)
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.
Example fix
// before from selenium.webdriver.chrome.service import Service svc = Service(executable_path="/usr/local/chromedriver") # not a file // after svc = Service() # let Selenium Manager resolve it
Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
p = "/usr/local/chromedriver"
assert Path(p).is_file(), f"driver path is not a file: {p}"
svc = Service(executable_path=p) Type guard
from pathlib import Path
def is_valid_driver_file(path) -> bool:
return Path(path).is_file() Try / catch
from selenium.common.exceptions import NoSuchDriverException
try:
driver = webdriver.Chrome(service=Service(executable_path=p))
except NoSuchDriverException as e:
print("cause:", e.__cause__)
driver = webdriver.Chrome() # fall back to Selenium Manager Prevention
- Verify Path(path).is_file() before passing executable_path.
- Prefer omitting executable_path to use Selenium Manager.
- Inspect NoSuchDriverException.__cause__ for the inner ValueError.
When it happens
Trigger: `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.
Common situations: 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.
Related errors
- The driver path is not a valid file: {output['driver_path']}
- The browser path is not a valid file: {output['browser_path'
- Unable to obtain driver for {browser}
- Path to the extension doesn't exist
- Storage state file not found: {file_path}
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/d4c23f524c36125e.
Report an issue: GitHub.