Skip to content

Instantly share code, notes, and snippets.

@bastman
Last active February 27, 2019 15:37
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 bastman/111079dc709704470209fa60d13d10fb to your computer and use it in GitHub Desktop.
Save bastman/111079dc709704470209fa60d13d10fb to your computer and use it in GitHub Desktop.
e2e-html-dom-selectors-xpath
document.querySelector('#region > div > div:nth-child(1) > span')
in chrome dev tools you can execute:
$x('//*[@id="region"]/div/div[1]/span')
which should be similar to ...
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
getElementByXpath('//*[@id="region"]/div/div[1]/span')
see: https://stackoverflow.com/questions/10596417/is-there-a-way-to-get-element-by-xpath-using-javascript-in-selenium-webdriver
you may want to install ChroPath extension: https://chrome.google.com/webstore/detail/chropath/ljngjbnaijcbncmcnjfhigebomdlkcjo/related?hl=en
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment