{"record":{"id":"a6227bcedd659d57","repo":"SeleniumHQ/selenium","slug":"argument-can-not-be-null","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/chromium/options.py","lineNumber":101,"sourceCode":"            with open(extension, \"rb\") as f:\n                encoded_extensions.append(_decode(f))\n\n        return encoded_extensions + self._extensions\n\n    def add_extension(self, extension: str) -> None:\n        \"\"\"Add the path to an extension to be extracted to ChromeDriver.\n\n        Args:\n            extension: Path to the *.crx file.\n        \"\"\"\n        if extension:\n            extension_to_add = os.path.abspath(os.path.expanduser(extension))\n            if os.path.exists(extension_to_add):\n                self._extension_files.append(extension_to_add)\n            else:\n                raise OSError(\"Path to the extension doesn't exist\")\n        else:\n            raise ValueError(\"argument can not be null\")\n\n    def add_encoded_extension(self, extension: str) -> None:\n        \"\"\"Add Base64-encoded string with extension data to be extracted to ChromeDriver.\n\n        Args:\n            extension: Base64 encoded string with extension data.\n        \"\"\"\n        if extension:\n            self._extensions.append(extension)\n        else:\n            raise ValueError(\"argument can not be null\")\n\n    @property\n    def experimental_options(self) -> dict:\n        \"\"\"Returns a dictionary of experimental options for chromium.\"\"\"\n        return self._experimental_options\n\n    def add_experimental_option(self, name: str, value: str | int | dict | list[str]) -> None:","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/chromium/options.py#L83-L119","documentation":"`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.","triggerScenarios":"`options.add_extension(\"\")`, `options.add_extension(None)`, or `options.add_extension(0)`. Often the result of a variable that was never assigned a path.","commonSituations":"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.","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."],"exampleFix":"// before\noptions.add_extension(config.get(\"crx_path\"))  # None when unset -> ValueError\n// after\nif crx := config.get(\"crx_path\"):\n    options.add_extension(crx)","handlingStrategy":"validation","validationCode":"ext_path = config.get(\"crx_path\") or \"\"\nif ext_path:\n    options.add_extension(ext_path)","typeGuard":"def is_non_empty(value) -> bool:\n    return bool(value)","tryCatchPattern":"try:\n    options.add_extension(ext_path)\nexcept ValueError:\n    # ext_path was empty; skip or assign a real path\n    ...","preventionTips":["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."],"tags":["options","extension","validation","chromium"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}