SeleniumHQ/selenium · error · WebDriverException
Detector has to be instance of FileDetector
Error message
Detector has to be instance of FileDetector
What it means
Raised by the file_detector setter when the value is non-None and truthy but is not an instance of FileDetector. The setter enforces the FileDetector contract so downstream send_keys logic can rely on the detector's API. This guard runs after the None check, so it only fires for objects that exist but are the wrong type.
Solutions
- Subclass FileDetector and instantiate it: from selenium.webdriver.remote.file_detector import FileDetector, LocalFileDetector.
- Make sure you assign an instance (LocalFileDetector()), not the class (LocalFileDetector).
- For tests/mocks, have the test double inherit from FileDetector rather than being a bare object.
Example fix
# before driver.file_detector = LocalFileDetector # class, not instance # after from selenium.webdriver.remote.file_detector import LocalFileDetector driver.file_detector = LocalFileDetector()
Defensive patterns
Strategy: type-guard
Validate before calling
from selenium.webdriver.remote.file_detector import FileDetector
if not isinstance(detector, FileDetector):
raise TypeError('detector must be a FileDetector instance')
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:
# likely wrong type; instantiate the correct class
driver.file_detector = LocalFileDetector() Prevention
- Assign instances, not classes: LocalFileDetector() not LocalFileDetector.
- Make test doubles inherit from FileDetector.
- Validate the type at the configuration boundary.
When it happens
Trigger: Assigning driver.file_detector to a plain object, a string, a bool, or a custom class that does not extend selenium.webdriver.remote.file_detector.FileDetector. Note: assigning True or 1 passes the None check (truthy) but fails isinstance, so it lands here.
Common situations: A developer passes a configuration object or a mock that does not subclass FileDetector. Or assigns LocalFileDetector (the class) instead of LocalFileDetector() (an instance) — the class object itself is not an instance of FileDetector.
Related errors
- You may not set a file detector that is null
- command_executor must be a RemoteConnection instance for…
- detector must respond to #call
- You are trying to upload something that isn't a file.
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/e512333ca379a5d5.
Report an issue: GitHub.
Appendix: source
Thrown at py/selenium/webdriver/remote/webdriver.py:1116
@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:
value: Orientation to set it to.
View on GitHub (pinned to aa36b38e69)