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.
Posted by Judith Roth to makandra dev (2017-02-09 11:14)