MCPcopy
hub / github.com/Fosowl/agenticSeek / getXPath

Function getXPath

sources/web_scripts/find_inputs.js:54–71  ·  view source on GitHub ↗
(element)

Source from the content-addressed store, hash-verified

52}
53// function to get the XPath of an element
54function getXPath(element) {
55 if (!element) return '';
56 if (element.id !== '') return '//*[@id="' + element.id + '"]';
57 if (element === document.body) return '/html/body';
58
59 let ix = 0;
60 const siblings = element.parentNode ? element.parentNode.childNodes : [];
61 for (let i = 0; i < siblings.length; i++) {
62 const sibling = siblings[i];
63 if (sibling === element) {
64 return getXPath(element.parentNode) + '/' + element.tagName.toLowerCase() + '[' + (ix + 1) + ']';
65 }
66 if (sibling.nodeType === 1 && sibling.tagName === element.tagName) {
67 ix++;
68 }
69 }
70 return '';
71}
72return findInputs(document.body);
73
74function isElementDisplayed(element) {

Callers 1

findInputsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected