SeleniumHQ/selenium · error · TypeError

service_args must be a sequence

Error message

service_args must be a sequence

What it means

Raised by the service_args setter on webkitgtk.Service when the assigned value is a str or is not a collections.abc.Sequence. Strings are explicitly rejected (even though str is technically a Sequence) to prevent accidentally passing a single argument string like '--verbose' when a list of individual argument strings is expected. The constructor accepts None or a Sequence and stores it as a list.

Source

Thrown at py/selenium/webdriver/webkitgtk/service.py:69

            executable_path=executable_path,
            port=port,
            log_output=log_output,
            env=env,
            **kwargs,
        )

    def command_line_args(self) -> list[str]:
        return ["-p", f"{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 or tuple of argument strings: service.service_args = ['--debug', '--port=1234'].
  2. If reading from a config string, split it first: args = config_str.split() or shlex.split(config_str).
  3. Pass service_args in the Service constructor instead of the setter, with the same list type.

Example fix

// before
service = Service()
service.service_args = '--debug --verbose'
// after
service = Service()
service.service_args = ['--debug', '--verbose']
Defensive patterns

Strategy: type-guard

Validate before calling

from collections.abc import Sequence

if isinstance(value, str) or not isinstance(value, Sequence):
    raise TypeError('service_args must be a sequence of strings')
service.service_args = list(value)

Type guard

from collections.abc import Sequence

def is_valid_service_args(value) -> bool:
    return not isinstance(value, str) and isinstance(value, Sequence) and all(isinstance(a, str) for a in value)

Try / catch

null

Prevention

When it happens

Trigger: Assigning service.service_args = '--debug' (a bare string) instead of ['--debug'] (a list); assigning an int, dict, or other non-sequence type; or assigning a single string argument where the API expects a list of separate flags.

Common situations: Configuring WebKitWebDriver with extra command-line arguments; migrating from a config format that stored args as a space-delimited string; copy-pasting CLI examples that show a string rather than a list; passing kwargs from a dictionary where the type was not validated upstream.

Related errors


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