SeleniumHQ/selenium · error · ValueError
argument can not be null
Error message
argument can not be null
What it means
`add_extension` rejects a falsy argument (empty string, None, etc.) with `ValueError("argument can not be null")`. An empty/None extension path is meaningless to chromedriver, so the library fails fast rather than silently queuing nothing. Note the parameter is typed `str` but the guard accepts any falsy value.
Source
Thrown at py/selenium/webdriver/chromium/options.py:101
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_options
def add_experimental_option(self, name: str, value: str | int | dict | list[str]) -> None:View on GitHub (pinned to aa36b38e69)
Solutions
- Guard before calling: `if ext_path: options.add_extension(ext_path)`.
- Validate config early and supply a real path or skip.
- Use `add_encoded_extension` if you have raw base64 data instead.
Example fix
// before
options.add_extension(config.get("crx_path")) # None when unset -> ValueError
// after
if crx := config.get("crx_path"):
options.add_extension(crx) Defensive patterns
Strategy: validation
Validate before calling
ext_path = config.get("crx_path") or ""
if ext_path:
options.add_extension(ext_path) Type guard
def is_non_empty(value) -> bool:
return bool(value) Try / catch
try:
options.add_extension(ext_path)
except ValueError:
# ext_path was empty; skip or assign a real path
... Prevention
- Guard with `if ext_path:` before calling add_extension.
- Treat empty/None extension paths as optional config.
- Validate config values at load time, not at use time.
When it happens
Trigger: `options.add_extension("")`, `options.add_extension(None)`, or `options.add_extension(0)`. Often the result of a variable that was never assigned a path.
Common situations: Config-driven setups where the extension path is optional and left empty. Reading from an env var that is unset (defaults to empty string). Looping over a list that contains an empty entry.
Related errors
- Path to the extension doesn't exist
- could not find extension at #{path.inspect}
- Couldn't find manifest.json in ${extension}
- Could not find add-on ID for ${extension}
- Binary Location Must be a String
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/a6227bcedd659d57.
Report an issue: GitHub.