{"record":{"id":"98a29a7a4027e17e","repo":"SeleniumHQ/selenium","slug":"android-package-must-be-passed-in","errorCode":null,"errorMessage":"android_package must be passed in","messagePattern":"android_package must be passed in","errorType":"validation","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/common/options.py","lineNumber":365,"sourceCode":"    def set_capability(self, name, value) -> None:\n        \"\"\"Sets a capability.\"\"\"\n        self._caps[name] = value\n\n    def enable_mobile(\n        self,\n        android_package: str | None = None,\n        android_activity: str | None = None,\n        device_serial: str | None = None,\n    ) -> None:\n        \"\"\"Enables mobile browser use for browsers that support it.\n\n        Args:\n            android_package: The name of the android package to start\n            android_activity: The name of the android activity\n            device_serial: The device serial number\n        \"\"\"\n        if not android_package:\n            raise AttributeError(\"android_package must be passed in\")\n        self.mobile_options = {\"androidPackage\": android_package}\n        if android_activity:\n            self.mobile_options[\"androidActivity\"] = android_activity\n        if device_serial:\n            self.mobile_options[\"androidDeviceSerial\"] = device_serial\n\n    @abstractmethod\n    def to_capabilities(self):\n        \"\"\"Convert options into capabilities dictionary.\"\"\"\n\n    @property\n    @abstractmethod\n    def default_capabilities(self):\n        \"\"\"Return minimal capabilities necessary as a dictionary.\"\"\"\n\n    def ignore_local_proxy_environment_variables(self) -> None:\n        \"\"\"Ignore HTTP_PROXY and HTTPS_PROXY environment variables.\"\"\"\n        self._ignore_local_proxy = True","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/common/options.py#L347-L383","documentation":"add_android_package / the mobile options method requires android_package to be a truthy value; passing None or an empty string raises AttributeError. This configures Chrome on Android (ChromeDriver mobile emulation) by populating mobile_options with androidPackage.","triggerScenarios":"Calling options.add_android_package(android_package=None) or with an empty string. Omitting the argument when calling programmatically with unpacked kwargs that resolve to None.","commonSituations":"Building options from config where the android package field is conditionally present. Forgetting that None is the default and passing it explicitly. Using an env var that is unset (resolving to '').","solutions":["Provide a non-empty android package name, e.g. 'com.android.chrome' or 'com.chrome.beta'.","Guard the call so it only runs when android_package is truthy."],"exampleFix":"# before\noptions.add_android_package(android_package=pkg)  # pkg is None -> AttributeError\n\n# after\nif pkg:\n    options.add_android_package(android_package=pkg)\n# or always pass a concrete value\noptions.add_android_package(android_package='com.android.chrome')","handlingStrategy":"validation","validationCode":"if not android_package:\n    raise ValueError('android_package is required for mobile options')\noptions.add_android_package(android_package=android_package)","typeGuard":"def has_android_package(v) -> bool:\n    return isinstance(v, str) and len(v) > 0","tryCatchPattern":"try:\n    options.add_android_package(android_package=pkg)\nexcept AttributeError:\n    # pkg was None/empty; skip or supply default\n    options.add_android_package(android_package='com.android.chrome')","preventionTips":["Guard the call with a truthiness check when the value is optional.","Centralize android package selection in config with a sensible default."],"tags":["options","android","mobile","validation"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}