Playing with DOM elements

There are a lot of things we can do with the page we are accessing beyond getting the title of the document, and this can be done with a little help from the Document Object Model API. We are not going to discuss each object and function of the DOM API, but we will touch on some that are very useful. If you want to learn more about DOM API, the best place to start is the Mozilla Development Network:

Selecting elements

Everything starts with the document object, and it contains nested elements. To select an element, we either traverse the entire document or use the DOM selectors. There are different methods to reference a document element, which can be done by element ID, class, ...

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.