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 `chrome.service.Service` validates its input: it explicitly rejects `str` (a common mistake since a string is technically a Sequence) and any non-Sequence type. Selenium needs a list of separate command-line flags to forward to the chromedriver process, so a single space-delimited string cannot be split reliably by the library. The check is `isinstance(value, str) or not isinstance(value, Sequence)`.

Source

Thrown at py/selenium/webdriver/chrome/service.py:73

            log_output=log_output,
            env=env,
            **kwargs,
        )

    def command_line_args(self) -> list[str]:
        # skip when CHROME_LOG_FILE is set; --enable-chrome-logs would override the user's log file
        args = [] if "CHROME_LOG_FILE" in self.env else ["--enable-chrome-logs"]
        return args + [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. If you have one combined string, split it first: `Service(service_args="--verbose".split())` or `shlex.split(flags)`.
  3. For logging specifically, prefer setting the `CHROME_LOG_FILE` env var or `--allow-storage-access` style flags as list items.

Example fix

// before
from selenium.webdriver.chrome.service import Service
svc = Service(service_args="--verbose --log-level=ALL")  # TypeError
// after
svc = Service(service_args=["--verbose", "--log-level=ALL"])
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

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

Try / catch

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

Prevention

When it happens

Trigger: Constructing `Service(service_args="--verbose --log-level=ALL")` (passing a single string), `Service(service_args="--verbose")`, `Service(service_args=42)`, or `Service(service_args={"a": 1})` (a dict is a Sequence of keys but used incorrectly). Setting `service.service_args = ...` after construction triggers the same setter.

Common situations: Copying examples from older blog posts that pass a single quoted string. Migrating from a CLI habit of one flag string. Passing a generator or iterator (not a Sequence). Passing a tuple works but is unusual.

Related errors


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