Skip to content

Instantly share code, notes, and snippets.

@unclebean
Created November 6, 2015 01:54
Show Gist options
  • Select an option

  • Save unclebean/9a040bc34af2d62d7bbe to your computer and use it in GitHub Desktop.

Select an option

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')]"));
@plh97
Copy link

plh97 commented Oct 5, 2024

then how to get Xpath by Element???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment