Use of scrollPosition to scroll to bottom

19 views
Skip to first unread message

Monish Gupta

unread,
May 30, 2016, 5:49:55 AM5/30/16
to phantomjs
Hi all,

I have a webpage with infinite scrolling. For this page, I need to scroll to bottom of the page. Following is the snippet of code I am trying to run:

    page.open(webPageUrl, function (status) {
        if (status !== 'success') {
            console.log('FAIL to load the address. ');
        }

        setTimeout(function(){
            page.evaluate(function() {
              // Scrolls to the bottom of page
              window.document.body.scrollTop = document.body.scrollHeight;
            });
        }, 10000);
    });


Question
1. Is the above approach correct and should work in PhantomJS?
2. Is there a way to verify if the scroll is actually happening? I tried following to check this:
  • I tried page.render before and after, both screenshots are same with no scrolling.
  • I tried getting values of body.scrollHeight before and after the above code snippet. Both giving value of 300. Seems like page.viewportSize is also not working for me.

 Any pointers would be a great help.
Thanks in advance!

Reply all
Reply to author
Forward
0 new messages