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

Function getElementString

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

Source from the content-addressed store, hash-verified

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) {
100 var attributes = [];
101 var attrNames = ["@type=", "@class=", "@name=", "@id="];
102 var attrValues = [element.type, element.className, element.name, element.id];
103
104 for (var i = attrNames.length - 1; i >= 0; i--) {
105 if (typeof attrValues[i] !== "undefined" && attrValues[i] !== "") {
106 attributes.push(attrNames[i] + "'" + attrValues[i] + "'");
107 }
108 }
109
110 if (attributes.length > 0) {
111 tagName += "[" + attributes.join(" and ") + "]";
112 }
113 }
114
115 if (siblingInfo.num > 0) {
116 tagName += "[" + siblingInfo.index + "]";
117 }
118
119 return tagName;
120 };
121
122 var buildPath = function(element, useAttributes) {
123 var path = getElementString(element, useAttributes);

Callers 1

buildPathFunction · 0.85

Calls 1

getSiblingInfoFunction · 0.85

Tested by

no test coverage detected