From 685d386dfc417c6e7789761c062224b6d833ae94 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Thu, 2 Nov 2017 11:14:12 -0500 Subject: [PATCH] Add Scroll To Top Of Page With Capybara as ruby til --- README.md | 3 ++- ruby/scroll-to-top-of-page-with-capybara.md | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 ruby/scroll-to-top-of-page-with-capybara.md diff --git a/README.md b/README.md index 7bcd745..1074780 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/). For a steady stream of TILs from a variety of rocketeers, checkout [til.hashrocket.com](https://til.hashrocket.com/). -_580 TILs and counting..._ +_581 TILs and counting..._ --- @@ -461,6 +461,7 @@ _580 TILs and counting..._ - [Returning With Sequel](ruby/returning-with-sequel.md) - [Running A Single MiniTest Example](ruby/running-a-single-minitest-example.md) - [Safe Navigation Operator](ruby/safe-navigation-operator.md) +- [Scroll To Top Of Page With Capybara](ruby/scroll-to-top-of-page-with-capybara.md) - [Set RVM Default Ruby](ruby/set-rvm-default-ruby.md) - [Show Public Methods With Pry](ruby/show-public-methods-with-pry.md) - [Squeeze Out The Extra Space](ruby/squeeze-out-the-extra-space.md) diff --git a/ruby/scroll-to-top-of-page-with-capybara.md b/ruby/scroll-to-top-of-page-with-capybara.md new file mode 100644 index 0000000..f32b33c --- /dev/null +++ b/ruby/scroll-to-top-of-page-with-capybara.md @@ -0,0 +1,12 @@ +# Scroll To Top Of Page With Capybara + +During a browser-based Capybara test, you may get partially scrolled down in +the page which can obscure or overlay DOM elements. A sure-fire way to +scroll back to the top is by executing the following line of JavaScript: + +```ruby +page.execute_script "window.scrollTo(0,0)" +``` + +This will scroll to `0,0` which is the top-most, left-most corner of the +browser.