Skip to content

Instantly share code, notes, and snippets.

@unclebean
Created November 6, 2015 01:54
Show Gist options
  • Save unclebean/9a040bc34af2d62d7bbe to your computer and use it in GitHub Desktop.
Save unclebean/9a040bc34af2d62d7bbe to your computer and use it in GitHub Desktop.
Get elements with XPath in javascript
//This function is from http://stackoverflow.com/questions/10596417/is-there-a-way-to-get-element-by-xpath-using-javascript-in-selenium-webdriver
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
console.log( getElementByXpath("//*[contains(text(), 'test')]"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment