Skip to content

Instantly share code, notes, and snippets.

@firedfox
Last active March 10, 2017 09:40
Show Gist options
  • Select an option

  • Save firedfox/fbb3e17e419b57308018 to your computer and use it in GitHub Desktop.

Select an option

Save firedfox/fbb3e17e419b57308018 to your computer and use it in GitHub Desktop.
// example:
// phantomjs getComputedStyle.js 'http://family.baidu.com/' '.item:last-child' 'font-size'
var webPage = require('webpage');
var system = require('system');
var page = webPage.create();
page.settings.loadImages = false;
var args = system.args;
if (args.length < 4) {
console.log('usage: phantomjs getComputedStyle.js url elementId styleName');
phantom.exit();
}
var url = args[1];
var elementId = args[2];
var styleName = args[3];
page.open(url, function(status) {
var styleValue = page.evaluate(function(elementId, styleName) {
var element = document.querySelector(elementId);
return window.getComputedStyle(element).getPropertyValue(styleName);
}, elementId, styleName);
console.log(styleValue);
phantom.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment