Auto scroll a button into view with Capybara and Selenium

This is a scroll bug that has shown up in Selenium and Chrome. The fix is https://stackoverflow.com/a/11048669/1935918


I normally have a module JavascriptDriver that I use to include Selenium functionality in a test, and there I define a helper method:

module JavascriptDriver
  # other code that prepares capybara to work with selenium

  def scroll_to(element)
    script = <<-JS
      arguments[0].scrollIntoView(true);
    JS

    Capybara.current_session.driver.browser.execute_script(script, element.native)
  end
end

And then in your test you can utilize that code by passing a normal Capybara element:

scroll_to(page.find("button.some-class", visible: false))