O'Reilly logo

PhantomJS Cookbook by Rob Friesel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Simulating scrolling in PhantomJS

This recipe introduces the scrollPosition property and how we can use it to simulate scrolling in PhantomJS.

Getting ready

To run this recipe, we will need a script that loads a web page tall enough (or wide enough) to scroll, and our script needs to expect to scroll the page.

The script in this recipe is available in the downloadable code repository as recipe09.js under chapter03. If we run the provided example script, we must change to the root directory for the book's sample code. Lastly, for this example to work, we will need an Internet connection.

How to do it…

Consider the following script:

var webpage = require('webpage').create(); webpage.viewportSize = { width: 1280, height: 800 }; webpage.scrollPosition = ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required