Created
October 28, 2019 10:29
-
-
Save navchandar/c6d484dec29b838611f0e0bafab84e54 to your computer and use it in GitHub Desktop.
Detect Elements by XPATH using pure JS
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
| function getElementsByXPath(xpath, parent) { | |
| let results=[]; | |
| let query = document.evaluate(xpath, parent||document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
| for(let i = 0,length = query.snapshotLength;i < length;++i){ | |
| results.push(query.snapshotItem(i)); | |
| } | |
| return results | |
| }; | |
| items = getElementsByXPath("//*"); | |
| items.length | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment