Skip to content

Instantly share code, notes, and snippets.

@cstorey
Created August 2, 2012 21:37
Show Gist options
  • Save cstorey/3240877 to your computer and use it in GitHub Desktop.
Save cstorey/3240877 to your computer and use it in GitHub Desktop.
Run an xpath expression against the current document
function nice_xpath(xp) {
var x = document.evaluate(xp, document.documentElement, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null, null);
if (x) {
var node = x.iterateNext();
while (node) {
console.log(node);
node = x.iterateNext();
}
}
}
var xp = ".//*[self::input | self::textarea][(./@id = //label[contains(normalize-space(string(.)), user_password)]/@for)]";
nice_xpath(xp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment