Skip to content

Instantly share code, notes, and snippets.

@sangupta
Created May 12, 2016 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sangupta/e3be131675159421d44dbf7cff9877c5 to your computer and use it in GitHub Desktop.
Save sangupta/e3be131675159421d44dbf7cff9877c5 to your computer and use it in GitHub Desktop.
The following script shows how to highlight a particular element on an HTML page using PhantomJS before taking a screenshot.
var webpage = require('webpage');
var page = webpage.create();
page.viewportSize = { width: 1600, height: 900 };
page.open('http://sangupta.com/poetry/best-of-luck.html', function() {
// execute the selector
var ev = page.evaluate(function(sel) {
var ele = document.querySelector(sel);
if(ele) {
ele.style.border = "2px solid red";
return true;
}
console.log('ele not found');
return false;
}, 'body > div.container-fluid.full-height > div > div.col-sm-3.col-md-2.sidebar > div > div > div:nth-child(3)');
// log the result
console.log('result is: ' + ev);
// take the snapshot
page.render('myscreenshot.png');
// exit phantomjs
phantom.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment