SeleniumHQ/selenium · error · AttributeError

android_package must be passed in

Error message

android_package must be passed in

What it means

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.

Source

Thrown at py/selenium/webdriver/common/options.py:365

    def set_capability(self, name, value) -> None:
        """Sets a capability."""
        self._caps[name] = value

    def enable_mobile(
        self,
        android_package: str | None = None,
        android_activity: str | None = None,
        device_serial: str | None = None,
    ) -> None:
        """Enables mobile browser use for browsers that support it.

        Args:
            android_package: The name of the android package to start
            android_activity: The name of the android activity
            device_serial: The device serial number
        """
        if not android_package:
            raise AttributeError("android_package must be passed in")
        self.mobile_options = {"androidPackage": android_package}
        if android_activity:
            self.mobile_options["androidActivity"] = android_activity
        if device_serial:
            self.mobile_options["androidDeviceSerial"] = device_serial

    @abstractmethod
    def to_capabilities(self):
        """Convert options into capabilities dictionary."""

    @property
    @abstractmethod
    def default_capabilities(self):
        """Return minimal capabilities necessary as a dictionary."""

    def ignore_local_proxy_environment_variables(self) -> None:
        """Ignore HTTP_PROXY and HTTPS_PROXY environment variables."""
        self._ignore_local_proxy = True

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Provide a non-empty android package name, e.g. 'com.android.chrome' or 'com.chrome.beta'.
  2. Guard the call so it only runs when android_package is truthy.

Example fix

# before
options.add_android_package(android_package=pkg)  # pkg is None -> AttributeError

# after
if pkg:
    options.add_android_package(android_package=pkg)
# or always pass a concrete value
options.add_android_package(android_package='com.android.chrome')
Defensive patterns

Strategy: validation

Validate before calling

if not android_package:
    raise ValueError('android_package is required for mobile options')
options.add_android_package(android_package=android_package)

Type guard

def has_android_package(v) -> bool:
    return isinstance(v, str) and len(v) > 0

Try / catch

try:
    options.add_android_package(android_package=pkg)
except AttributeError:
    # pkg was None/empty; skip or supply default
    options.add_android_package(android_package='com.android.chrome')

Prevention

When it happens

Trigger: 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.

Common situations: 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 '').

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/98a29a7a4027e17e. Report an issue: GitHub.