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

Updated . Posted . Visible to the public.

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.

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.

Judith Roth
Last edit
Judith Roth
Attachments
License
Source code in this card is licensed under the MIT License.
Posted by Judith Roth to makandra dev (2017-02-09 11:14)