Read more

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

Judith Roth
February 09, 2017Software engineer at makandra GmbH

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 Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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 by Judith Roth to makandra dev (2017-02-09 12:14)