{"record":{"id":"5140b3646fe984fe","repo":"SeleniumHQ/selenium","slug":"argument-can-not-be-null-5140b3","errorCode":null,"errorMessage":"argument can not be null","messagePattern":"argument can not be null","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/common/options.py","lineNumber":409,"sourceCode":"    def __init__(self) -> None:\n        super().__init__()\n        self._arguments: list[str] = []\n\n    @property\n    def arguments(self):\n        \"\"\"Returns a list of arguments needed for the browser.\"\"\"\n        return self._arguments\n\n    def add_argument(self, argument: str) -> None:\n        \"\"\"Adds an argument to the list.\n\n        Args:\n            argument: Sets the arguments\n        \"\"\"\n        if argument:\n            self._arguments.append(argument)\n        else:\n            raise ValueError(\"argument can not be null\")\n\n    def ignore_local_proxy_environment_variables(self) -> None:\n        \"\"\"Ignore HTTP_PROXY and HTTPS_PROXY environment variables.\n\n        This method is deprecated; use a Proxy instance with ProxyType.DIRECT instead.\n        \"\"\"\n        warnings.warn(\n            \"using ignore_local_proxy_environment_variables in Options has been deprecated, \"\n            \"instead, create a Proxy instance with ProxyType.DIRECT to ignore proxy settings, \"\n            \"pass the proxy instance into a ClientConfig constructor, \"\n            \"pass the client config instance into the Webdriver constructor\",\n            DeprecationWarning,\n            stacklevel=2,\n        )\n\n        super().ignore_local_proxy_environment_variables()\n\n    def to_capabilities(self):","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/common/options.py#L391-L427","documentation":"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.","triggerScenarios":"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 ''.","commonSituations":"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.","solutions":["Filter falsy entries before adding: [a for a in args if a].","Ensure the argument is a non-empty string."],"exampleFix":"# before\nfor a in raw_args.split(' '):\n    options.add_argument(a)  # '' from trailing space -> ValueError\n\n# after\nfor a in raw_args.split(' '):\n    if a:\n        options.add_argument(a)","handlingStrategy":"validation","validationCode":"for a in args:\n    if not a:\n        continue\n    options.add_argument(a)\n# or filter upfront\nclean_args = [a for a in args if a]","typeGuard":"def is_valid_argument(v) -> bool:\n    return isinstance(v, str) and len(v.strip()) > 0","tryCatchPattern":"try:\n    options.add_argument(a)\nexcept ValueError:\n    pass  # skip falsy/empty arguments","preventionTips":["Filter empty strings from split arg lists before adding.","Avoid appending None when building args programmatically."],"tags":["options","arguments","validation"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}