SeleniumHQ/selenium · error · TypeError

service_args must be a sequence

Error message

service_args must be a sequence

What it means

The `service_args` setter on `chromium.service.ChromiumDriverService` (the shared base for Chrome/Edge) validates its input identically to the chrome-specific service: it rejects `str` and any non-Sequence type. It needs a list of separate flags to forward to the driver binary. This is the base class version that the chrome and edge services inherit.

Source

Thrown at py/selenium/webdriver/chromium/service.py:93

            port=port,
            env=env,
            log_output=self.log_output,
            driver_path_env_key=driver_path_env_key,
            **kwargs,
        )

    def command_line_args(self) -> list[str]:
        return [f"--port={self.port}"] + self._service_args

    @property
    def service_args(self) -> Sequence[str]:
        """Returns the sequence of service arguments."""
        return self._service_args

    @service_args.setter
    def service_args(self, value: Sequence[str]):
        if isinstance(value, str) or not isinstance(value, Sequence):
            raise TypeError("service_args must be a sequence")
        self._service_args = list(value)

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Pass a list of flags: `Service(service_args=["--verbose", "--log-level=ALL"])`.
  2. Split a combined string: `Service(service_args=shlex.split(flags))`.
  3. Prefer structured logging config (e.g. `--readable-timestamp`) as discrete list items.

Example fix

// before
from selenium.webdriver.chromium.utils import ...  # or edge service
svc = Service(service_args="--verbose")  # TypeError
// after
svc = Service(service_args=["--verbose"])
Defensive patterns

Strategy: type-guard

Validate before calling

from collections.abc import Sequence
flags = "--verbose"
assert not isinstance(flags, str) and isinstance(flags, Sequence), "pass a list of flags"
service_args = list(flags)

Type guard

from collections.abc import Sequence
def is_valid_service_args(value) -> bool:
    return not isinstance(value, str) and isinstance(value, Sequence)

Try / catch

try:
    svc = Service(service_args=flags)
except TypeError:
    import shlex
    svc = Service(service_args=shlex.split(flags) if isinstance(flags, str) else list(flags))

Prevention

When it happens

Trigger: `Service(service_args="--verbose")` for Edge or Chromium, `Service(service_args="--log-level=ALL --append-log")`, or `service.service_args = 5`. Same shape as the chrome-specific error but raised from the chromium base.

Common situations: Edge or Chromium users hitting the same single-string habit. Copying a flag string from a shell command. Passing a generator expression.

Related errors


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