2

I'm trying to use Watir (via Ruby) to jump down the page using the space key, on a page that has infinite scroll. How can I tell if the bottom of the page has been reached?

I found an SO answer with some JavaScript that says when. Could I use that to pop up a dialog (via execute_script) if the bottom has been reached and check for the dialog?

Is there a more straightforward way to do this?

halfer
  • 19,824
  • 17
  • 99
  • 186
ian
  • 12,003
  • 9
  • 51
  • 107

1 Answers1

1

You could just try this:

@browser.scroll.to :bottom

And if that doesn't work:

@browser.driver.executeScript("if((window.innerHeight+window.scrollY)>=document.body.offsetHeight){return true;}")

could surely be used to scroll until it returns true.

Hans VK
  • 124
  • 8
  • 1
    The first one scrolls fine but doesn't indicate when I've reached the bottom. The second one returns the info but the javascript doesn't always work! (o_O) Being able to get feedback via the script though is immensely helpful, thank you, I'll be able to get further with this now. – ian Nov 24 '15 at 23:59
  • 2
    This js appears to work `br.execute_script("if (document.body.scrollHeight == document.body.scrollTop + window.innerHeight) { return true; } else { return false; }")`. I think you did enough for the tick! :) – ian Nov 25 '15 at 00:10