Cucumber Capybara scroll to bottom of page
27,563
Solution 1
I solved this with visit '#footer'
inside a "scroll to the bottom of the page" step.
Solution 2
You could use javascript to achieve this:
page.execute_script "window.scrollBy(0,10000)"
Solution 3
A solution without jQuery or adapts to any height without magic numbers:
page.execute_script('window.scrollTo(0, document.body.scrollHeight)')
Author by
Eric M.
Updated on September 23, 2021Comments
-
Eric M. almost 3 years
I'd like to use my Cucumber/Capybara setup to test endless scroll by driving a browser and scrolling to the bottom of the page to ensure that the new content is loaded. Is there a way to do this?
-
Nat Ritmeyer almost 11 yearsThis only works if you have an element with an
id
offooter
. It also assumes (reasonably) that the footer is at the bottom of the page... -
lukas.pukenis over 10 yearsGenious. +1 even though not a direct answer ;))
-
lukas.pukenis over 10 years@NatRitmeyer well yes... That's why it's called footer, yes?
-
Nat Ritmeyer over 10 yearsIndeed :) But have you never seen a #footer that isn't at the bottom of the page?
-
Dan Kohn over 9 yearsFor Google purposes, I got here with the error "unknown error: Element is not clickable at point (750, 341). Other element would receive the click" and the solution was
page.execute_script "window.scrollBy(0,500)"
. Thanks! -
Drew about 8 yearsIf you have jQuery available you can run
window.scrollBy(0, $(window).height())
-
igorsantos07 about 7 yearsmore than discussing where the footer is placed, it assumes the footer was loaded! I got here looking for a way to take page screenshots of the bottom parts and, if there's some failure on the page, that method won't work :/ The JS solution is a bit safer in those cases.
-
ZedTuX over 5 yearsUnfortunately, this doesn't work in my Angular app, I don't know why yet.
-
taystack about 5 yearsThis is good but it doesn't work for javascript SPAs that have
#
in the route. (sad face) -
Arnaud Meuret over 4 yearsTo be just as nitpicky as your comment on visit '#footer', this only works if your page is less than 10000 units high.
-
Nat Ritmeyer over 4 years@ArnaudMeuret I salute your pedantry :)