MCPcopy Index your code
hub / github.com/browsemake/browser-cli / generateXPath

Function generateXPath

daemon.js:276–292  ·  view source on GitHub ↗
(node, parentNode)

Source from the content-addressed store, hash-verified

274 let idToXPath = {};
275
276 function generateXPath(node, parentNode) {
277 if (!node || node.nodeName === '#document') {
278 return '';
279 }
280
281 const tagName = node.nodeName.toLowerCase();
282 let segment = tagName;
283
284 if (parentNode && parentNode.children) {
285 const siblings = parentNode.children.filter(child => child.nodeName === node.nodeName);
286 if (siblings.length > 1) {
287 const index = siblings.indexOf(node) + 1;
288 segment += `[${index}]`;
289 }
290 }
291 return segment;
292 }
293
294 function traverseDomAndMap(node, parentXPath = '', parentNode = null) {
295 if (!node) return;

Callers 1

traverseDomAndMapFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected