Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Javascript find by XPath
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
console.log( getElementByXpath("//html[1]/body[1]/div[1]") );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment