From 23a4b6512fc4dee537915279f21fd4b309d344d6 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Mon, 2 Oct 2017 11:55:13 -0700 Subject: [PATCH] Attempt to move element into view when selenium doesn't correctly do it --- lib/capybara/selenium/node.rb | 8 ++++++++ .../spec/views/with_fixed_header_footer.erb | 17 +++++++++++++++++ spec/shared_selenium_session.rb | 10 ++++++++++ 3 files changed, 35 insertions(+) create mode 100644 lib/capybara/spec/views/with_fixed_header_footer.erb diff --git a/lib/capybara/selenium/node.rb b/lib/capybara/selenium/node.rb index 4cf780dc..8f584594 100644 --- a/lib/capybara/selenium/node.rb +++ b/lib/capybara/selenium/node.rb @@ -100,6 +100,14 @@ class Capybara::Selenium::Node < Capybara::Driver::Node def click native.click + rescue => e + if e.message =~ /Other element would receive the click/ + begin + driver.execute_script("arguments[0].scrollIntoView({behavior: 'instant', block: 'center', inline: 'center'})", self) + rescue + end + end + raise e end def right_click diff --git a/lib/capybara/spec/views/with_fixed_header_footer.erb b/lib/capybara/spec/views/with_fixed_header_footer.erb new file mode 100644 index 00000000..826748c8 --- /dev/null +++ b/lib/capybara/spec/views/with_fixed_header_footer.erb @@ -0,0 +1,17 @@ + + + + + +
My headers
+
+
A tall block
+ Go to root +
+ + \ No newline at end of file diff --git a/spec/shared_selenium_session.rb b/spec/shared_selenium_session.rb index 87d62988..690f5375 100644 --- a/spec/shared_selenium_session.rb +++ b/spec/shared_selenium_session.rb @@ -191,5 +191,15 @@ RSpec.shared_examples "Capybara::Session" do |session, mode| expect(el.inspect).to eq "Obsolete #" end end + + describe "Element#click" do + it "should handle fixed headers/footers" do + pending "geckodriver/firefox/marionette just fail to click without reporting an error - no way for us to detect/catch" if mode == :selenium_marionette + @session.visit('/with_fixed_header_footer') + # @session.click_link('Go to root') + @session.find(:link, 'Go to root').click + expect(@session).to have_current_path('/') + end + end end end