Skip to content Skip to sidebar Skip to footer

Scroll Down Page Event For X Seconds

I am currently able to scroll down a page with the help of CasperJS. I saw this article on how to scroll infinite pages based on the visibility of certain attributes. However I don

Solution 1:

Here's a simple way:

function tryAndScroll(casper) {
    casper.page.scrollPosition = {
        top: casper.page.scrollPosition["top"] + 300,
        left: 0
    };
}

casper.start(url).then(function() {
    var self = this;
    var intervalId = setInterval(function(){
        tryAndScroll(self);
    }, 100); // retry interval
    self.wait(10000 /* infinite scroll timeout */, function(){
        clearInterval(intervalId);
    });
}).run();

Since setInterval() is not a CasperJS step function, this essentially break out of the control flow of CasperJS. The wait() is necessary so that CasperJS doesn't execute something else during the scroll.

Also, you can't use a scroll distance of 40000 pixels. This is too big and PhantomJS won't be able to take a screenshot.


Post a Comment for "Scroll Down Page Event For X Seconds"