Skip to main content

Command Palette

Search for a command to run...

WebDriverError: You are trying to upload something that isn't a file.

Updated
2 min read
WebDriverError: You are trying to upload something that isn't a file.
V

I am an accomplished Solution Architect, Full Stack Developer and DevOps Specialist with a passion for creative leadership and mentorship, business optimization and technical direction, and ingenious solutions to complex problems.

I am especially interested in App & Web Development, Cyber Security, Cloud Computing, Data Science, Open Source Software, Statistical Analysis and Discrete Mathematics.

Occasionally, when running Ruby on Rails system tests with Selenium WebDriver in Gitlab CI, you will receive an error such as this:

.....2024-07-31 05:18:51 ERROR Selenium [:file_detector] File detector only works with files. "test" isn`t a file! 
[Screenshot Image]: /builds/projects/example/tmp/screenshots/failures_test_should_show_validation_errors_for_password_and_password_confirmation.png
E
Error:
Devise::RegistrationsTest#test_should_show_validation_errors_for_password_and_password_confirmation:
Selenium::WebDriver::Error::WebDriverError: You are trying to upload something that isn't a file.
    test/system/devise/registrations_test.rb:42:in `block (2 levels) in <class:RegistrationsTest>'
    test/system/devise/registrations_test.rb:37:in `each'
    test/system/devise/registrations_test.rb:37:in `block in <class:RegistrationsTest>'
bin/rails test test/system/devise/registrations_test.rb:36

This error corresponds to registrations_test.rb:42, which looks like this:

fill_in 'Password', with: 'test'

And the form field that is being filled in is defined as:

f.password_field :password

The error "You are trying to upload something that isn't a file." makes absolutely no sense, as no file is being uploaded, and the associated screenshot shows that the value test is not being filled in for the password field.

So, what's going on here?

Solution

💡
Avoid using the test value for password fields.

For some reason, the value test invokes a file uploader within Selenium WebDriver; hence, the following change fixes the error in Gitlab CI:

fill_in 'Password', with: 'abc-def'

The mystery of why the value test does not work will remain unsolved, though the most likely cause is a Selenium Webdriver bug, but at least system tests work again when executed in CI mode.

D

Great post! Thanks for sharing! I ran into the same issue on a work project and noticed something interesting: we had a folder named test at the project root. When I experimented with other folder names like lib, app, etc. as values to fill the form field, I got the same error message. Then, when I tried actual filenames like Rakefile or README, I wouldn't get the error, but the field would be filled with the path to that file (or a temporary copy of it). So, it turns out that if the string you use to fill the input field matches the path to any file or folder in your project directory, Selenium WebDriver will try to upload that file/folder as if it was a file input, regardless of the actual input type. It's seems a bit less like a Selenium bug, but rather an overly aggressive file detection feature that checks if form values correspond to existing filesystem paths.

More from this blog

K

Konoson Tech Chronicles

22 posts

Technical insights on web development, DevOps, and system architecture with practical guides and real-world solutions.