selenium file detector not working for remote uploads
Fixes file uploads on remote selenium sessions where the file detector is not set. Use it when `send_keys` with a local path fails on Grid or cloud drivers. Not for local driver uploads or non-file input issues.
TL;DR
On a remote driver, send_keys("/local/path/file.png") sends the literal string to the remote machine, which does not have your file; that is why uploads silently fail on Grid or cloud providers. The fix is setting a file detector on the remote driver (driver.file_detector = LocalFileDetector() in Python), which zips and transfers the local file before the keys are sent. Local drivers do not need this, which is why the same test passes locally and fails remotely.
The query
selenium file detector not working for remote uploadsUse this when
- File upload works locally but fails on Grid / cloud selenium
- The remote input receives a path string instead of the file
- Migrating a suite from local drivers to remote
Not for
- Local driver file uploads
- Drag-and-drop file uploads onto drop zones
- Non-input custom upload widgets (may need JS workarounds)
Steps
- Confirm the driver is remote and that no file detector is set (uploads send the raw local path). Expected output: you verify the failure only happens on remote sessions.
- Set
driver.file_detector = LocalFileDetector()right after creating the remote driver (equivalent APIs exist in Java and other bindings). Expected output: no error; the detector is attached to the session. - Re-run the upload with an absolute local file path via
send_keyson the file input. Expected output: the file transfers and the input's value shows the uploaded filename. - Assert the app-side result (preview, success message, or listed file). Expected output: the application confirms the upload completed.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_oLh7g5zLwba1FWAuzPUaWQ
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.