{"record":{"id":"94abb1da879cea72","repo":"SeleniumHQ/selenium","slug":"you-may-not-set-a-file-detector-that-is-null","errorCode":null,"errorMessage":"You may not set a file detector that is null","messagePattern":"You may not set a file detector that is null","errorType":"validation","errorClass":"WebDriverException","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/remote/webdriver.py","lineNumber":1114,"sourceCode":"\n        return self.execute(Command.SET_WINDOW_RECT, {\"x\": x, \"y\": y, \"width\": width, \"height\": height})[\"value\"]\n\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:","sourceCodeStart":1096,"sourceCodeEnd":1132,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/remote/webdriver.py#L1096-L1132","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["To disable local-file upload, assign the no-op detector: from selenium.webdriver.remote.file_detector import UselessFileDetector; driver.file_detector = UselessFileDetector().","Ensure the detector variable is actually instantiated before assignment, not left as None from a failed import.","Do not use falsy sentinels like 0 or '' — only FileDetector subclass instances are accepted."],"exampleFix":"# before\ndriver.file_detector = None\n\n# after\nfrom selenium.webdriver.remote.file_detector import UselessFileDetector\ndriver.file_detector = UselessFileDetector()","handlingStrategy":"validation","validationCode":"from selenium.webdriver.remote.file_detector import UselessFileDetector\ndetector = detector if detector is not None else UselessFileDetector()\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    from selenium.webdriver.remote.file_detector import UselessFileDetector\n    driver.file_detector = UselessFileDetector()","preventionTips":["Never assign None; use UselessFileDetector() to disable upload detection.","Centralize detector creation so a failed import surfaces early rather than producing None.","Type-check detectors at the boundary where they are configured."],"tags":["file-upload","property-setter","argument-validation"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}