Read more

Bug in Chrome 56+ prevents filling in fields with slashes using selenium-webdriver/Capybara

Deleted user #4117
February 09, 2017Software engineer

There seems to be a nasty bug in Chrome 56 when testing with Selenium and Capybara: Slashes are not written to input fields with fill_in. A workaround is to use javascript / jquery to change the contents of an input field.

Illustration online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
Read more Show archive.org snapshot

Use the following code or add the attached file to your features/support/-directory to overwrite fill_in.

module ChromedriverWorkarounds

  def fill_in(locator, options = {})
    text = options[:with].to_s
    if Capybara.current_driver == :selenium && text.include?('/')
      # There is a nasty Bug in Chrome 56+ which fails to write slashes into
      # text fields for unknown reasons.
      field = find_field(locator)
      id = field[:id].presence
      if id
        execute_script <<~JAVASCRIPT
          var field = document.querySelector('##{id}');
          field.value = #{text.to_json};
          field.dispatchEvent(new Event('input'));
          field.dispatchEvent(new Event('change'));
        JAVASCRIPT
      else
        raise "Tried to work around a Chromedriver bug, but that requires the #{locator.inspect} field to have an ID."
      end
    else
      super(locator, options)
    end
  end

end
World(ChromedriverWorkarounds)

The same issue was seen in Chrome 72 and 73.


A similar issue was seen in Chrome 65 with current Selenium-Webdriver (3.11) and chromedriver (2.37), where strings containing slashes (HTML) would be completely mangled.

Posted to makandra dev (2017-02-09 12:14)