SeleniumHQ/selenium · error · TypeError
Only children of '{cls.__name__}' may be instantiated
Error message
Only children of '{cls.__name__}' may be instantiated What it means
Raised by LocalWebDriver.__new__ when someone attempts to instantiate the LocalWebDriver base class directly (cls is LocalWebDriver). LocalWebDriver is an abstract base for local browser drivers (Chrome, Firefox, Edge, Safari) and enforces instantiation only of concrete subclasses via __new__ rather than ABCMeta.
Source
Thrown at py/selenium/webdriver/common/webdriver.py:30
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
class LocalWebDriver(RemoteWebDriver):
"""Base class for local WebDrivers."""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._is_remote = False
def __new__(cls, *args, **kwargs):
if cls is LocalWebDriver:
raise TypeError(f"Only children of '{cls.__name__}' may be instantiated")
return object.__new__(cls)
def quit(self) -> None:
"""Closes the browser and shuts down the driver executable."""
try:
super().quit()
except Exception:
# We don't care about the message because something probably has gone wrong
pass
finally:
if hasattr(self, "service") and self.service is not None:
self.service.stop()
def download_file(self, *args, **kwargs):
"""Only implemented in RemoteWebDriver."""
raise NotImplementedError
def get_downloadable_files(self, *args, **kwargs):View on GitHub (pinned to aa36b38e69)
Solutions
- Instantiate a concrete driver instead: webdriver.Chrome(), webdriver.Firefox(), webdriver.Edge(), or webdriver.Safari().
- If building a factory, ensure the resolved class is never LocalWebDriver itself.
- Import the concrete driver class, not selenium.webdriver.common.webdriver.LocalWebDriver.
Example fix
# before from selenium.webdriver.common.webdriver import LocalWebDriver driver = LocalWebDriver() # -> TypeError # after from selenium import webdriver driver = webdriver.Chrome()
Defensive patterns
Strategy: type-guard
Validate before calling
from selenium.webdriver.common.webdriver import LocalWebDriver assert cls is not LocalWebDriver, 'Instantiate a concrete driver (Chrome/Firefox/Edge/Safari)'
Type guard
def is_concrete_local_driver(cls) -> bool:
from selenium.webdriver.common.webdriver import LocalWebDriver
return cls is not LocalWebDriver and issubclass(cls, LocalWebDriver) Try / catch
null
Prevention
- Never import or instantiate LocalWebDriver directly.
- Use selenium.webdriver.Chrome / Firefox / Edge / Safari.
- In factories, validate the resolved class is a concrete subclass.
When it happens
Trigger: Writing `driver = LocalWebDriver()` directly, or dynamically constructing a class where the resolved class object is exactly LocalWebDriver rather than a subclass. This is a programmer error, not an environmental issue.
Common situations: Mistakenly importing LocalWebDriver instead of a concrete driver, building a generic driver factory that falls back to the base class, or misconfigured dynamic imports resolving to the base.
Related errors
- Params must be an instance of CookieFilter. Received:'${cook
- Unknown error: ${JSON.stringify(data)}
- ${message}
- Level must be >= 0
- not a string or number
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/a431c8b8d5a1f711.
Report an issue: GitHub.