Attempt to move element into view when selenium doesn't correctly do it

This commit is contained in:
Thomas Walpole 2017-10-02 11:55:13 -07:00
parent 9b8dbb9b68
commit 23a4b6512f
3 changed files with 35 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,17 @@
<html>
<head>
<style>
header { height: 45px; position: fixed; top: 0; background-color: red; width: 100%;}
footer { height: 45px; position: fixed; bottom: 0; background-color: red; width: 100%;}
#main { margin: 45px;}
#tall { display: block; height: 2000px;}
</style>
</head>
<body>
<header>My headers</header>
<div id="main">
<div id="tall">A tall block</div>
<a href="/">Go to root</a>
</div>
<footer>My footer</footer>
</body>

View File

@ -191,5 +191,15 @@ RSpec.shared_examples "Capybara::Session" do |session, mode|
expect(el.inspect).to eq "Obsolete #<Capybara::Node::Element>"
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