SeleniumHQ/selenium · error · Error::WebDriverError

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

Error message

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

What it means

Raised as Error::WebDriverError by the upload method (mixed in via Remote::Features) when the file_detector callback returned a path that is not a regular file (File.file? returns false). The upload flow zips the local file and sends it to the remote server via execute :upload_file; only real files can be zipped, so directories, broken symlinks, devices, or non-existent paths are rejected.

Source

Thrown at rb/lib/selenium/webdriver/remote/features.rb:48

        }.freeze

        def add_commands(commands)
          @command_list = command_list.merge(commands)
        end

        def command_list
          @command_list ||= REMOTE_COMMANDS
        end

        def commands(command)
          command_list[command]
        end

        def upload(local_file)
          unless File.file?(local_file)
            WebDriver.logger.error("File detector only works with files. #{local_file.inspect} isn`t a file!",
                                   id: :file_detector)
            raise Error::WebDriverError, "You are trying to upload something that isn't a file."
          end

          execute :upload_file, {}, {file: Zipper.zip_file(local_file)}
        end

        def upload_if_necessary(keys)
          local_files = keys.first&.split("\n")&.filter_map { |key| @file_detector.call(Array(key)) }
          return keys unless local_files&.any?

          keys = local_files.map { |local_file| upload(local_file) }
          Array(keys.join("\n"))
        end

        def downloadable_files
          execute :get_downloadable_files
        end

        def download_file(name)

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Verify the file exists and is a regular file before triggering upload: File.file?(path).
  2. Use absolute paths and ensure the file is present on the machine running the WebDriver client (not just the remote node).
  3. If using a custom file_detector, ensure it only returns paths that pass File.file?.
  4. In CI, copy test fixtures into a known local directory and reference those paths.

Example fix

# before
upload_element.send_keys('/data/uploads/avatar')  # is a directory

# after
upload_element.send_keys('/data/uploads/avatar.png')  # a real file
# guard:
path = '/data/uploads/avatar.png'
upload_element.send_keys(path) if File.file?(path)
Defensive patterns

Strategy: validation

Validate before calling

# Validate file before triggering upload:
filepath = '/path/to/file.png'
raise ArgumentError, "#{filepath} is not a regular file" unless File.file?(filepath)
upload_element.send_keys(filepath)

Type guard

def uploadable_file?(path)
  path.is_a?(String) && File.file?(path)
end

Try / catch

begin
  upload_element.send_keys(filepath)
rescue Selenium::WebDriver::Error::WebDriverError => e
  raise unless e.message.include?("isn't a file")
  # locate the real file or skip the upload
  raise "File not found for upload: #{filepath}"
end

Prevention

When it happens

Trigger: Calling driver.send_keys with a path to a directory, a non-existent file, a broken symlink, or a special device file. The default file_detector or a custom one returning a path string where File.file? is false. Using send_keys with text that the file_detector misinterprets as a file path.

Common situations: Uploading from a path that doesn't exist in the test runner's filesystem (common in containerized or CI environments where the file is on a different volume). Race condition where the file is deleted between detection and upload. Passing an absolute path from a different OS (Windows path on Linux runner). A custom file_detector with a bug returning directory paths.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/ea8d9df6f891f8cd. Report an issue: GitHub.