SeleniumHQ/selenium · error · OSError
Path to the extension doesn't exist
Error message
Path to the extension doesn't exist
What it means
`add_extension` checks that the given path resolves to an existing file on disk (after `abspath`/`expanduser` expansion) before queuing it as a `.crx` extension to load. If the file does not exist it raises `OSError`. This guards chromedriver from receiving a missing-file path.
Source
Thrown at py/selenium/webdriver/chromium/options.py:99
encoded_extensions = []
for extension in self._extension_files:
with open(extension, "rb") as f:
encoded_extensions.append(_decode(f))
return encoded_extensions + self._extensions
def add_extension(self, extension: str) -> None:
"""Add the path to an extension to be extracted to ChromeDriver.
Args:
extension: Path to the *.crx file.
"""
if extension:
extension_to_add = os.path.abspath(os.path.expanduser(extension))
if os.path.exists(extension_to_add):
self._extension_files.append(extension_to_add)
else:
raise OSError("Path to the extension doesn't exist")
else:
raise ValueError("argument can not be null")
def add_encoded_extension(self, extension: str) -> None:
"""Add Base64-encoded string with extension data to be extracted to ChromeDriver.
Args:
extension: Base64 encoded string with extension data.
"""
if extension:
self._extensions.append(extension)
else:
raise ValueError("argument can not be null")
@property
def experimental_options(self) -> dict:
"""Returns a dictionary of experimental options for chromium."""
return self._experimental_optionsView on GitHub (pinned to aa36b38e69)
Solutions
- Verify the path exists: `if not os.path.exists(path): raise ...` before calling.
- Use an absolute path resolved against the script location: `pathlib.Path(__file__).parent / "ext.crx"`.
- If you only have the encoded extension data, use `add_encoded_extension` instead.
- Check `os.path.isfile(path)` (not just exists) to also catch directory paths.
Example fix
// before
options.add_extension("ext.crx") # fails if CWD differs
// after
import pathlib
ext = pathlib.Path(__file__).parent / "ext.crx"
options.add_extension(str(ext)) Defensive patterns
Strategy: validation
Validate before calling
import os
ext = "ext.crx"
if not os.path.isfile(os.path.abspath(os.path.expanduser(ext))):
raise FileNotFoundError(ext)
options.add_extension(ext) Type guard
import os
def is_existing_extension_file(path: str) -> bool:
return bool(path) and os.path.isfile(os.path.abspath(os.path.expanduser(path))) Try / catch
try:
options.add_extension(ext_path)
except OSError:
# log and either locate the file or use add_encoded_extension
... Prevention
- Anchor extension paths to the script directory with pathlib.
- Prefer add_encoded_extension when shipping the payload in code.
- Use os.path.isfile (not just exists) to reject directories.
When it happens
Trigger: `options.add_extension("/wrong/path/ext.crx")`, `options.add_extension("~/notthere.crx")`, relative paths that resolve outside the CWD, or a path to a directory instead of a `.crx` file.
Common situations: Bundling extensions in a CI artifact whose path changed. Relative paths breaking when the script runs from a different working directory. Typos in the path. Downloading a `.crx` that failed.
Related errors
- could not find extension at #{path.inspect}
- argument can not be null
- could not find extension at #{path.inspect}
- Binary Location Must be a String
- could not find extension at #{path.inspect}
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/dffc1f9594c35200.
Report an issue: GitHub.