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 wpewebkit.Service when the assigned value is a str or is not a collections.abc.Sequence. Identical validation to the webkitgtk Service class: strings are explicitly rejected to prevent passing a single argument string when a list of argument strings is expected.

Source

Thrown at py/selenium/webdriver/wpewebkit/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. Split config strings before assignment: args = shlex.split(config_str).
  3. Pass service_args in the constructor with the same list type.

Example fix

// before
service.service_args = '--debug'
// after
service.service_args = ['--debug']
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' (bare string) instead of ['--debug']; assigning a non-sequence type like int or dict; passing a space-delimited string of flags where the API expects a list.

Common situations: Configuring WPEWebDriver with extra command-line arguments; config-driven arg passing where the format is a string; migrating from a format that did not enforce types; copy-pasting CLI-style arguments.

Related errors


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