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

Function getElementInfo_Custom

util/xpath_utils.js:42–146  ·  view source on GitHub ↗
(element, useAttributes)

Source from the content-addressed store, hash-verified

40 * Custom XPath generation with optional attribute-based targeting
41 */
42export function getElementInfo_Custom(element, useAttributes) {
43 var getSiblingInfo = function(element, useAttributes) {
44 var info = { num: 0, index: 1 };
45 var prevCount = 0;
46 var nextCount = 0;
47 var prevSibling = element.previousSibling;
48 var nextSibling = element.nextSibling;
49
50 if (useAttributes) {
51 while (prevSibling !== null) {
52 if (prevSibling.id === element.id &&
53 prevSibling.tagName === element.tagName &&
54 prevSibling.name === element.name &&
55 prevSibling.className === element.className &&
56 prevSibling.type === element.type) {
57 prevCount += 1;
58 }
59 prevSibling = prevSibling.previousSibling;
60 }
61 while (nextSibling !== null) {
62 if (nextSibling.id === element.id &&
63 nextSibling.tagName === element.tagName &&
64 nextSibling.name === element.name &&
65 nextSibling.className === element.className &&
66 nextSibling.type === element.type) {
67 nextCount += 1;
68 }
69 nextSibling = nextSibling.nextSibling;
70 }
71 } else {
72 while (prevSibling !== null) {
73 if (prevSibling.tagName === element.tagName) {
74 prevCount += 1;
75 }
76 prevSibling = prevSibling.previousSibling;
77 }
78 while (nextSibling !== null) {
79 if (nextSibling.tagName === element.tagName) {
80 nextCount += 1;
81 }
82 nextSibling = nextSibling.nextSibling;
83 }
84 }
85
86 info.num = prevCount + nextCount;
87 info.index += prevCount;
88 return info;
89 };
90
91 var getElementString = function(element, useAttributes) {
92 // Check if element has tagName property
93 if (!element || !element.tagName) {
94 return '';
95 }
96 var tagName = element.tagName.toLowerCase();
97 var siblingInfo = getSiblingInfo(element, useAttributes);
98
99 if (useAttributes) {

Callers 1

getXpathsFunction · 0.85

Calls 1

buildPathFunction · 0.85

Tested by

no test coverage detected