{"record":{"id":"6aaf8e7dde2217de","repo":"SeleniumHQ/selenium","slug":"this-method-needs-to-be-implemented-in-a-sub-class","errorCode":null,"errorMessage":"This method needs to be implemented in a sub class","messagePattern":"This method needs to be implemented in a sub class","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/common/service.py","lineNumber":89,"sourceCode":"            self.log_output = log_output\n\n        self.port = port or utils.free_port()\n        # Default value for every python subprocess: subprocess.Popen(..., creationflags=0)\n        self.popen_kw = kwargs.pop(\"popen_kw\", {})\n        self.creation_flags = self.popen_kw.pop(\"creation_flags\", 0)\n        self.env = env or os.environ\n        self.DRIVER_PATH_ENV_KEY = driver_path_env_key\n        self._path = self.env_path() or executable_path\n\n    @property\n    def service_url(self) -> str:\n        \"\"\"Gets the url of the Service.\"\"\"\n        return f\"http://{utils.join_host_port('localhost', self.port)}\"\n\n    @abstractmethod\n    def command_line_args(self) -> list[str]:\n        \"\"\"A List of program arguments (excluding the executable).\"\"\"\n        raise NotImplementedError(\"This method needs to be implemented in a sub class\")\n\n    @property\n    def path(self) -> str:\n        return self._path or \"\"\n\n    @path.setter\n    def path(self, value: str) -> None:\n        self._path = str(value)\n\n    def start(self) -> None:\n        \"\"\"Starts the Service.\n\n        Raises:\n            WebDriverException: Raised either when it can't start the service\n                or when it can't connect to the service\n        \"\"\"\n        if self._path is None:\n            raise WebDriverException(\"Service path cannot be None.\")","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/common/service.py#L71-L107","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Implement command_line_args() in your Service subclass returning the list of CLI flags for your driver (e.g. [f'--port={self.port}']).","Do not instantiate the base Service class directly — use the browser-specific Service (ChromeService, GeckoService, EdgeService).","If you need a custom service, inherit from the closest concrete service rather than the abstract base."],"exampleFix":"# before — missing override\n# class MyService(Service):\n#     pass\n\nclass MyService(Service):\n    def command_line_args(self):\n        return [f'--port={self.port}', '--verbose']","handlingStrategy":"type-guard","validationCode":"from selenium.webdriver.common.service import Service\nclass MyService(Service):\n    def command_line_args(self):\n        return [f'--port={self.port}']\nassert MyService.command_line_args is not Service.command_line_args, 'override missing'","typeGuard":"def has_command_line_args_override(cls) -> bool:\n    return 'command_line_args' in cls.__dict__  # True only if defined directly on the subclass","tryCatchPattern":"null","preventionTips":["Always implement command_line_args when subclassing Service.","Inherit from the closest concrete browser Service rather than the abstract base.","Add a unit test asserting your subclass overrides command_line_args."],"tags":["service","abstract-method","subclassing","api-contract"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}