Skip to content

Instantly share code, notes, and snippets.

Created June 29, 2014 18:48
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 anonymous/94351cd8644251e9b878 to your computer and use it in GitHub Desktop.
Save anonymous/94351cd8644251e9b878 to your computer and use it in GitHub Desktop.
var page = require('webpage').create();
page.onConsoleMessage = function(msg) {
console.log('CONSOLE: ' + msg);
};
page.onError = function(msg, trace) {
console.log('ERROR: ' + msg + (trace ? ("trace: " + JSON.stringify(trace)) : ""));
};
page.content = "<div id='a'>some text</div><p id='b'>more text</p>";
setTimeout(function(){
page.evaluate(function(){
console.log(!!document.querySelector("div#a")); // true
console.log(!!document.querySelector("div[id='a']")); // true
console.log(!!document.querySelector("div:not([id='a'])")); // false
console.log(!!document.querySelector("p:not([id='a'])")); // true
console.log(!!document.querySelector("div[id!='a']")); // error
});
}, 1000);
setTimeout(function(){
phantom.exit();
}, 2000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment