SeleniumHQ/selenium · error · WebDriverException

You may not set a file detector that is null

Error message

You may not set a file detector that is null

What it means

Raised by the file_detector property setter when the assigned detector is falsy (None, empty, etc.). Selenium uses a file detector to decide whether to transparently upload local files during send_keys; it must never be None because the driver internals assume a valid detector exists. A generic WebDriverException (not an InvalidArgumentException) is thrown because the setter predates stricter typing.

Source

Thrown at py/selenium/webdriver/remote/webdriver.py:1114

        return self.execute(Command.SET_WINDOW_RECT, {"x": x, "y": y, "width": width, "height": height})["value"]

    @property
    def file_detector(self) -> FileDetector:
        return self._file_detector

    @file_detector.setter
    def file_detector(self, detector) -> None:
        """Set the file detector for keyboard input.

        By default, this is set to a file detector that does nothing.
        See FileDetector, LocalFileDetector, and UselessFileDetector.

        Args:
            detector: The detector to use. Must not be None.
        """
        if not detector:
            raise WebDriverException("You may not set a file detector that is null")
        if not isinstance(detector, FileDetector):
            raise WebDriverException("Detector has to be instance of FileDetector")
        self._file_detector = detector

    @property
    def orientation(self) -> dict:
        """Gets the current orientation of the device.

        Example:
            `orientation = driver.orientation`
        """
        return self.execute(Command.GET_SCREEN_ORIENTATION)["value"]

    @orientation.setter
    def orientation(self, value) -> None:
        """Sets the current orientation of the device.

        Args:

View on GitHub (pinned to aa36b38e69)

Solutions

  1. To disable local-file upload, assign the no-op detector: from selenium.webdriver.remote.file_detector import UselessFileDetector; driver.file_detector = UselessFileDetector().
  2. Ensure the detector variable is actually instantiated before assignment, not left as None from a failed import.
  3. Do not use falsy sentinels like 0 or '' — only FileDetector subclass instances are accepted.

Example fix

# before
driver.file_detector = None

# after
from selenium.webdriver.remote.file_detector import UselessFileDetector
driver.file_detector = UselessFileDetector()
Defensive patterns

Strategy: validation

Validate before calling

from selenium.webdriver.remote.file_detector import UselessFileDetector
detector = detector if detector is not None else UselessFileDetector()
driver.file_detector = detector

Type guard

from selenium.webdriver.remote.file_detector import FileDetector
def is_file_detector(d) -> bool:
    return isinstance(d, FileDetector)

Try / catch

from selenium.common.exceptions import WebDriverException
try:
    driver.file_detector = detector
except WebDriverException:
    from selenium.webdriver.remote.file_detector import UselessFileDetector
    driver.file_detector = UselessFileDetector()

Prevention

When it happens

Trigger: Assigning driver.file_detector = None, or assigning any falsy value (0, empty string, empty object). The check `if not detector` runs before the isinstance check, so it catches None first.

Common situations: A developer tries to 'disable' file upload detection by setting the detector to None, or clears a previously-set LocalFileDetector by assigning None. Also happens when a detector variable is conditionally constructed and ends up None.

Related errors


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