Home > Net >  Selenium WebDriver for AWS Device Farm error when sending period "." keystroke to element
Selenium WebDriver for AWS Device Farm error when sending period "." keystroke to element

Time:12-22

I'm moving test execution of RSpec/Capybara tests to AWS Device Farm. I'm having an issue when sending an individual period (".") to a field. Here is my binding.pry debug session:

[5] pry(#<RSpec::ExampleGroups::Drivers>)> find('input[id^="filter"]').set('.')
Selenium::WebDriver::Error::WebDriverError: You are trying to work with something that isn't a file.
from /Users/pfong/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/selenium-webdriver-4.0.3/lib/selenium/webdriver/remote/bridge.rb:422:in `upload'

It works fine if I send multiple characters. However in this case I'm looking to send one key at a time slowly in another helper method.

I'm not sure why it thinks I'm sending a file when I'm clearly trying to hit keystrokes.

CodePudding user response:

Looks like this is a bug/feature in selenium-webdriver - when keys are sent to an element the following code is called

def send_keys_to_element(element, keys)
      # TODO: rework file detectors before Selenium 4.0
      if @file_detector
        local_files = keys.first&.split("\n")&.map { |key| @file_detector.call(Array(key)) }&.compact
        if local_files.any?
          keys = local_files.map { |local_file| upload(local_file) }
          keys = Array(keys.join("\n"))
        end
      end
      ...
    end

Selenium 4 changed to have a default file detector on the remote driver defined as

->((filename, *)) { File.exist?(filename) && filename.to_s }

so that is triggering because '.' does exist (the current directory). A workaround would be to reset the driver file_detector to nil after it's created.

current_session.driver.browser.file_detector = nil
  • Related