SeleniumHQ/selenium · error · NotImplementedError

This method needs to be implemented in a sub class

Error message

This method needs to be implemented in a sub class

What it means

Raised by the abstract Service.command_line_args() method, which is decorated with @abstractmethod and exists to be overridden by every concrete service subclass (ChromeService, GeckoService, EdgeService, etc.). Calling the base implementation directly means a subclass forgot to override it. In practice the @abstractmethod decorator blocks instantiation first, so seeing this at runtime usually indicates someone bypassed ABC checks or called the unbound method directly.

Source

Thrown at py/selenium/webdriver/common/service.py:89

            self.log_output = log_output

        self.port = port or utils.free_port()
        # Default value for every python subprocess: subprocess.Popen(..., creationflags=0)
        self.popen_kw = kwargs.pop("popen_kw", {})
        self.creation_flags = self.popen_kw.pop("creation_flags", 0)
        self.env = env or os.environ
        self.DRIVER_PATH_ENV_KEY = driver_path_env_key
        self._path = self.env_path() or executable_path

    @property
    def service_url(self) -> str:
        """Gets the url of the Service."""
        return f"http://{utils.join_host_port('localhost', self.port)}"

    @abstractmethod
    def command_line_args(self) -> list[str]:
        """A List of program arguments (excluding the executable)."""
        raise NotImplementedError("This method needs to be implemented in a sub class")

    @property
    def path(self) -> str:
        return self._path or ""

    @path.setter
    def path(self, value: str) -> None:
        self._path = str(value)

    def start(self) -> None:
        """Starts the Service.

        Raises:
            WebDriverException: Raised either when it can't start the service
                or when it can't connect to the service
        """
        if self._path is None:
            raise WebDriverException("Service path cannot be None.")

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Implement command_line_args() in your Service subclass returning the list of CLI flags for your driver (e.g. [f'--port={self.port}']).
  2. Do not instantiate the base Service class directly — use the browser-specific Service (ChromeService, GeckoService, EdgeService).
  3. If you need a custom service, inherit from the closest concrete service rather than the abstract base.

Example fix

# before — missing override
# class MyService(Service):
#     pass

class MyService(Service):
    def command_line_args(self):
        return [f'--port={self.port}', '--verbose']
Defensive patterns

Strategy: type-guard

Validate before calling

from selenium.webdriver.common.service import Service
class MyService(Service):
    def command_line_args(self):
        return [f'--port={self.port}']
assert MyService.command_line_args is not Service.command_line_args, 'override missing'

Type guard

def has_command_line_args_override(cls) -> bool:
    return 'command_line_args' in cls.__dict__  # True only if defined directly on the subclass

Try / catch

null

Prevention

When it happens

Trigger: Subclassing Service without overriding command_line_args() and then bypassing the ABC instantiation guard (e.g. via __new__ tricks or object.__new__), or calling Service.command_line_args() explicitly on the base class. Also reachable if a future refactor accidentally removes the override from a concrete subclass while disabling ABC enforcement.

Common situations: Writing a custom driver Service subclass and forgetting to implement command_line_args(), or copy-pasting the base class as a template and not filling in the method.

Related errors


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