Last active
March 5, 2019 09:14
-
-
Save bspavel/895af8030a6298ef09760ea76198c9b9 to your computer and use it in GitHub Desktop.
document.getElementByXpath
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //https://stackoverflow.com/questions/12689768/how-can-i-extend-the-document-object | |
| //https://stackoverflow.com/questions/10596417/is-there-a-way-to-get-element-by-xpath-using-javascript-in-selenium-webdriver | |
| if (typeof HTMLDocument !== 'undefined') { | |
| HTMLDocument.prototype.getElementByXpath=function (path) { | |
| return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
| }; | |
| } else { | |
| Document.prototype.getElementByXpath=function (path) { | |
| return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
| }; | |
| } | |
| console.log( document.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