Created
March 21, 2025 13:22
-
-
Save gunesmes/68eb7e5603ffb7208ec8b0afc315be03 to your computer and use it in GitHub Desktop.
Javascript getElementsByXPath by using document
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
// Find elements with Xpath | |
function getElementsByXPath(xpath, doc) { | |
const iterator = doc.evaluate( | |
xpath, | |
doc, | |
null, | |
4, | |
null | |
);s | |
const elements = []; | |
let current = iterator.iterateNext(); | |
while (current) { | |
elements.push(current); | |
current = iterator.iterateNext(); | |
} | |
return elements; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment