SeleniumHQ/selenium · error · ValueError
argument can not be null
Error message
argument can not be null
What it means
add_argument rejects falsy values (None, empty string, 0) because the code uses a truthiness check `if argument:`. Any empty/None argument raises ValueError. Note that a string of only whitespace (' ') is truthy and would be accepted, so this guards emptiness, not validity.
Source
Thrown at py/selenium/webdriver/common/options.py:409
def __init__(self) -> None:
super().__init__()
self._arguments: list[str] = []
@property
def arguments(self):
"""Returns a list of arguments needed for the browser."""
return self._arguments
def add_argument(self, argument: str) -> None:
"""Adds an argument to the list.
Args:
argument: Sets the arguments
"""
if argument:
self._arguments.append(argument)
else:
raise ValueError("argument can not be null")
def ignore_local_proxy_environment_variables(self) -> None:
"""Ignore HTTP_PROXY and HTTPS_PROXY environment variables.
This method is deprecated; use a Proxy instance with ProxyType.DIRECT instead.
"""
warnings.warn(
"using ignore_local_proxy_environment_variables in Options has been deprecated, "
"instead, create a Proxy instance with ProxyType.DIRECT to ignore proxy settings, "
"pass the proxy instance into a ClientConfig constructor, "
"pass the client config instance into the Webdriver constructor",
DeprecationWarning,
stacklevel=2,
)
super().ignore_local_proxy_environment_variables()
def to_capabilities(self):View on GitHub (pinned to aa36b38e69)
Solutions
- Filter falsy entries before adding: [a for a in args if a].
- Ensure the argument is a non-empty string.
Example fix
# before
for a in raw_args.split(' '):
options.add_argument(a) # '' from trailing space -> ValueError
# after
for a in raw_args.split(' '):
if a:
options.add_argument(a) Defensive patterns
Strategy: validation
Validate before calling
for a in args:
if not a:
continue
options.add_argument(a)
# or filter upfront
clean_args = [a for a in args if a] Type guard
def is_valid_argument(v) -> bool:
return isinstance(v, str) and len(v.strip()) > 0 Try / catch
try:
options.add_argument(a)
except ValueError:
pass # skip falsy/empty arguments Prevention
- Filter empty strings from split arg lists before adding.
- Avoid appending None when building args programmatically.
When it happens
Trigger: Calling options.add_argument(None), options.add_argument(''), or options.add_argument(0). Common when arguments come from a list that contains an empty entry, e.g. splitting an arg string that yields ''.
Common situations: Parsing args from a config/env var that is unset. Splitting '--flag ' which yields an empty trailing element. Building args programmatically and accidentally appending None.
Related errors
- argument can not be null
- Strategy can only be one of the following: normal, eager, no
- Behavior can only be one of the following: dismiss, accept,
- Timeout keys can only be one of the following: implicit, pag
- android_package must be passed in
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/5140b3646fe984fe.
Report an issue: GitHub.