From 3a471e5f0abedee4cf3f838ab0ab44487159730b Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Mon, 28 Dec 2020 09:18:18 -0800 Subject: [PATCH] Check if field is already focused when sending keys with FF --- lib/capybara/selenium/driver.rb | 2 +- lib/capybara/selenium/nodes/firefox_node.rb | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/capybara/selenium/driver.rb b/lib/capybara/selenium/driver.rb index 6bb3824f..b7452074 100644 --- a/lib/capybara/selenium/driver.rb +++ b/lib/capybara/selenium/driver.rb @@ -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 diff --git a/lib/capybara/selenium/nodes/firefox_node.rb b/lib/capybara/selenium/nodes/firefox_node.rb index e1cd6bd1..dd2d65ba 100644 --- a/lib/capybara/selenium/nodes/firefox_node.rb +++ b/lib/capybara/selenium/nodes/firefox_node.rb @@ -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