1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Merge pull request #2430 from teamcapybara/feature/ff_focus_send_keys

Check if field is already focused when sending keys with FF
This commit is contained in:
Thomas Walpole 2021-01-17 20:56:22 -08:00 committed by GitHub
commit a6d506a263
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 2 deletions

View file

@ -6,6 +6,7 @@ Release date: unreleased
* :button selector type use with `enable_aria_role` [Sean Doyle]
* <label> elements don't associate with aria-role buttons
* Ignore Selenium::WebDriver::Error::InvalidSessionIdError when quitting driver [Robin Daugherty]
* Firefox: Don't click input when sending keys if already focused
# Version 3.34.0
Release date: 2020-11-26

View file

@ -66,7 +66,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
end
end
processed_options = options.reject { |key, _val| SPECIAL_OPTIONS.include?(key) }
@browser = Selenium::WebDriver.for(options[:browser], processed_options)
@browser = Selenium::WebDriver.for(options[:browser], **processed_options)
specialize_driver
setup_exit_handler

View file

@ -40,11 +40,16 @@ class Capybara::Selenium::FirefoxNode < Capybara::Selenium::Node
path_names.each { |path| native.send_keys(path) }
end
def focused?
driver.evaluate_script('arguments[0] == document.activeElement', self)
end
def send_keys(*args)
# https://github.com/mozilla/geckodriver/issues/846
return super(*args.map { |arg| arg == :space ? ' ' : arg }) if args.none?(Array)
native.click
native.click unless focused?
_send_keys(args).perform
end