I'm using Selenium Webdriver to get the content of a webpage. The page loads more content as the user scrolls down using AJAX. I am able to scroll down using javascript, but don't know when to stop scrolling. How do I know when I can't scroll down anymore? I can't use document.clientheight or any of the height properties, because they deal with scrolling when the window is too small but the elements are all attached to the DOM and their height is therefore known. Here, the elements are being dynamically attached to the DOM, so the height is not known in advance.
How do I know when I've reached the bottom? Is there a "scrollbar is not scrollable" condition available somewhere? Or will that also be triggered if more content is loading and the scrollbar is not yet available to scroll, but soon will be?
Thanks, bsg
Update
The answer that worked for me was actually given to another question of mine (this one was a more precise subset of that one). Namely, use jquery to test the following equivalence: $(document).height() == ($(window).height() + $(window).scrollTop();. If it evaluates to true, you've reached the bottom of the page. (For an explanation of why this works, see Meaning of $(window).scrollTop() == $(document).height() - $(window).height()) I'm not sure if this would work without jquery, so if the page you're testing doesn't have jquery, you probably should use user1177636's answer below.
The exact code I used was:
JavascriptExecutor js = (JavascriptExecutor)driver;
do{
//scroll down and do whatever processing you need
reachedbottom = Boolean.parseBoolean(js.executeScript("return $(document).height() == ($(window).height() + $(window).scrollTop());").toString());
}while(!reachedbottom);
Hope this helps someone.