Performing user events
In some cases, we will need to emulate user keyboard events and mouse events. PhantomJS provides a simple function to trigger these events from our script. These events will provide necessary actions in our script, from clicking on a URL to inputting usernames and passwords, or just filling up a form.
The function sendEvent
, from the WebPage API, has the capability to perform these events on the page from our scripts.
page.sendEvent(eventType[,event specific arguments])
There are two types of events that are supported: keyboard and mouse events. Each event differs by the set of arguments that can be passed to the functions to match the necessary data to perform the event.
Keyboard events
Let us first explore how to use key events. ...
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.