Simulating mouse clicks

Web pages are built with interlocking links, and getting to another page can be done by following that link. In a normal browser, this is done by clicking with your mouse button. In PhantomJS there are two ways to do this: one is by using PhantomJS sendEvent functions (PhantomJS event triggering); the other is by using DOM event triggering.

PhantomJS event triggering

The WebPage API supports sending events to the page. This can be mouse events or keyboard events. We will discuss more events as we progress, but for now we will tackle how to simulate clicking on page elements and links using PhantomJS event triggering.

PhantomJS Mouse Event Triggering API

sendEvent( eventType, Point X, Point Y, button='left' )

eventType ...

Get Getting Started with PhantomJS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.