crunchit
Version:
Autotrack the events from your users
18 lines (15 loc) • 370 B
JavaScript
function getElementByXPath(path) {
while (path.includes("{")) {
path = path.replace(/\{\w.*?\}/g, "");
}
let evaluator = new XPathEvaluator();
let result = evaluator.evaluate(
path,
document.documentElement,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
);
return result.singleNodeValue;
}
module.exports = getElementByXPath;