Skip to content

Instantly share code, notes, and snippets.

@bjeanes
Created March 2, 2017 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjeanes/3aa9c29b87030c7e527feacb217b97d5 to your computer and use it in GitHub Desktop.
Save bjeanes/3aa9c29b87030c7e527feacb217b97d5 to your computer and use it in GitHub Desktop.
# Chromedriver has this annoying bug where when trying to click a button or
# something which is obscured by another element due to scrolling, it fails to
# click the button or link.
#
# This is a workaround to always scroll the element into view after finding it.
module Capybara
module Chrome
module Finders
def find(*args)
super(*args).tap do |node|
if Capybara::Selenium::Driver === (driver = Capybara.current_session.driver)
if (browser = driver.browser).browser.to_s =~ /chrome/
browser.execute_script('arguments[0].scrollIntoView(false);', node.native)
end
end
end
end
end
end
end
Capybara::Node::Base.send :include, Capybara::Chrome::Finders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment