MCPcopy Create free account
hub / github.com/InverseUI/InverseUI-Recorder / getXpaths

Function getXpaths

util/xpath_utils.js:7–37  ·  view source on GitHub ↗
(element)

Source from the content-addressed store, hash-verified

5 * Returns array of unique, validated XPaths
6 */
7export function getXpaths(element) {
8 if (!element || !element.tagName) return [];
9
10 var paths = [];
11 paths.push(getElementInfo_Custom(element, false));
12 paths.push(getElementInfo_Custom(element, true));
13 paths.push(getElementInfo_Moz(element));
14
15 // Deduplicate paths
16 var unique = paths.filter(function(path, index, self) {
17 return path && self.indexOf(path) === index;
18 });
19
20 // Validate each XPath
21 unique = unique.filter(function(xpath) {
22 try {
23 var result = document.evaluate(xpath, document, null, XPathResult.ANY_TYPE, null);
24 var count = 0;
25 var node = result.iterateNext();
26 while (node) {
27 count++;
28 node = result.iterateNext();
29 }
30 return count === 1; // Only return unique XPaths
31 } catch (e) {
32 return false;
33 }
34 });
35
36 return unique;
37}
38
39/**
40 * Custom XPath generation with optional attribute-based targeting

Callers 3

clickListenerFunction · 0.85
inputListenerFunction · 0.85
initializeRecordingFunction · 0.85

Calls 2

getElementInfo_CustomFunction · 0.85
getElementInfo_MozFunction · 0.85

Tested by

no test coverage detected