Skip to content

Instantly share code, notes, and snippets.

@gunesmes
Created March 21, 2025 13:22
Show Gist options
  • Save gunesmes/68eb7e5603ffb7208ec8b0afc315be03 to your computer and use it in GitHub Desktop.
Save gunesmes/68eb7e5603ffb7208ec8b0afc315be03 to your computer and use it in GitHub Desktop.
Javascript getElementsByXPath by using document
// 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