{"record":{"id":"e512333ca379a5d5","repo":"SeleniumHQ/selenium","slug":"detector-has-to-be-instance-of-filedetector","errorCode":null,"errorMessage":"Detector has to be instance of FileDetector","messagePattern":"Detector has to be instance of FileDetector","errorType":"validation","errorClass":"WebDriverException","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/remote/webdriver.py","lineNumber":1116,"sourceCode":"\n    @property\n    def file_detector(self) -> FileDetector:\n        return self._file_detector\n\n    @file_detector.setter\n    def file_detector(self, detector) -> None:\n        \"\"\"Set the file detector for keyboard input.\n\n        By default, this is set to a file detector that does nothing.\n        See FileDetector, LocalFileDetector, and UselessFileDetector.\n\n        Args:\n            detector: The detector to use. Must not be None.\n        \"\"\"\n        if not detector:\n            raise WebDriverException(\"You may not set a file detector that is null\")\n        if not isinstance(detector, FileDetector):\n            raise WebDriverException(\"Detector has to be instance of FileDetector\")\n        self._file_detector = detector\n\n    @property\n    def orientation(self) -> dict:\n        \"\"\"Gets the current orientation of the device.\n\n        Example:\n            `orientation = driver.orientation`\n        \"\"\"\n        return self.execute(Command.GET_SCREEN_ORIENTATION)[\"value\"]\n\n    @orientation.setter\n    def orientation(self, value) -> None:\n        \"\"\"Sets the current orientation of the device.\n\n        Args:\n            value: Orientation to set it to.\n","sourceCodeStart":1098,"sourceCodeEnd":1134,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/remote/webdriver.py#L1098-L1134","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\ndriver.file_detector = LocalFileDetector  # class, not instance\n\n# after\nfrom selenium.webdriver.remote.file_detector import LocalFileDetector\ndriver.file_detector = LocalFileDetector()","handlingStrategy":"type-guard","validationCode":"from selenium.webdriver.remote.file_detector import FileDetector\nif not isinstance(detector, FileDetector):\n    raise TypeError('detector must be a FileDetector instance')\ndriver.file_detector = detector","typeGuard":"from selenium.webdriver.remote.file_detector import FileDetector\ndef is_file_detector(d) -> bool:\n    return isinstance(d, FileDetector)","tryCatchPattern":"from selenium.common.exceptions import WebDriverException\ntry:\n    driver.file_detector = detector\nexcept WebDriverException:\n    # likely wrong type; instantiate the correct class\n    driver.file_detector = LocalFileDetector()","preventionTips":["Assign instances, not classes: LocalFileDetector() not LocalFileDetector.","Make test doubles inherit from FileDetector.","Validate the type at the configuration boundary."],"tags":["file-upload","type-checking","property-setter"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}