From 63197387f9033802838b9b95876b4749a1574657 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Sat, 31 Aug 2019 13:23:44 -0700 Subject: [PATCH] Move common file input click emulation behavior into module --- History.md | 2 +- .../selenium/extensions/file_input_click_emulation.rb | 8 ++++++++ lib/capybara/selenium/nodes/chrome_node.rb | 4 ---- lib/capybara/selenium/nodes/firefox_node.rb | 4 ---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/History.md b/History.md index d8e54cfa..457d4c54 100644 --- a/History.md +++ b/History.md @@ -3,7 +3,7 @@ Release date: Unreleased ### Added -* Allow clicking on file input when using the block version of `attach_file` with Chrome +* Allow clicking on file input when using the block version of `attach_file` with Chrome and Firefox * Spatial filters (`left_of`, `right_of`, `above`, `below`, `near`) * rack_test driver now supports clicking on details elements to open/close them diff --git a/lib/capybara/selenium/extensions/file_input_click_emulation.rb b/lib/capybara/selenium/extensions/file_input_click_emulation.rb index 8f4e4015..6f033588 100644 --- a/lib/capybara/selenium/extensions/file_input_click_emulation.rb +++ b/lib/capybara/selenium/extensions/file_input_click_emulation.rb @@ -2,6 +2,14 @@ class Capybara::Selenium::Node module FileInputClickEmulation + def click(keys = [], **options) + super + rescue Selenium::WebDriver::Error::InvalidArgumentError + return emulate_click if attaching_file? && visible_file_field? + + raise + end + private def visible_file_field? diff --git a/lib/capybara/selenium/nodes/chrome_node.rb b/lib/capybara/selenium/nodes/chrome_node.rb index 7b136b05..16a34de9 100644 --- a/lib/capybara/selenium/nodes/chrome_node.rb +++ b/lib/capybara/selenium/nodes/chrome_node.rb @@ -36,10 +36,6 @@ class Capybara::Selenium::ChromeNode < Capybara::Selenium::Node def click(*) super - rescue Selenium::WebDriver::Error::InvalidArgumentError - return emulate_click if attaching_file? && visible_file_field? - - raise rescue ::Selenium::WebDriver::Error::ElementClickInterceptedError raise rescue ::Selenium::WebDriver::Error::WebDriverError => e diff --git a/lib/capybara/selenium/nodes/firefox_node.rb b/lib/capybara/selenium/nodes/firefox_node.rb index c2ed3546..b3c9305b 100644 --- a/lib/capybara/selenium/nodes/firefox_node.rb +++ b/lib/capybara/selenium/nodes/firefox_node.rb @@ -9,10 +9,6 @@ class Capybara::Selenium::FirefoxNode < Capybara::Selenium::Node def click(keys = [], **options) super - rescue Selenium::WebDriver::Error::InvalidArgumentError - return emulate_click if attaching_file? && visible_file_field? - - raise rescue ::Selenium::WebDriver::Error::ElementNotInteractableError if tag_name == 'tr' warn 'You are attempting to click a table row which has issues in geckodriver/marionette - '\