I took this from a previous answer
var iterations = 5; //amount of pages to go through var timeToWait = 2000; //time to wait in milliseconds var last; var list = []; for (i = 0; i <= iterations; i++) { list.push(i); } //evaluate this in the browser context and pass the timer back to casperjs casper.thenEvaluate(function(iters, waitTime) { window.x = 0; var intervalID = setInterval(function() { console.log("Using setInternal " + window.x); window.scrollTo(0, document.body.scrollHeight); if (++window.x === iters) { window.clearInterval(intervalID); } }, waitTime); }, iterations, timeToWait); casper.each(list, function(self, i) { self.wait(timeToWait, function() { last = i; this.echo('Using this.wait ' + i); }); }); casper.waitFor(function() { return (last === list[list.length - 1] && iterations === this.getGlobal('x')); }, function() { this.echo('All done.') });
Essentially, I enter the context of the page, scroll to the bottom and then wait 2 seconds to load the content. Obviously, I would like to use repeated applications of casper.scrollToBottom() or something more complicated, but the loading time did not allow me to do this.
anguyen
source share