XPath Test in Browser Console (listed) 11.01.2023 11:41:04 (17 lines) [Edit] [Raw] [View]

//just a quick function for copy/pasting into the console function xpath(path, root) { return document.evaluate(path, root || document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; }

//more js-styled functions 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; }

function getElementByXPath(path, root) { return document.evaluate(path, root || document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; }