MCPcopy Create free account
hub / github.com/ChromeDevTools/devtools-frontend / xPathValue

Function xPathValue

front_end/panels/elements/DOMPath.ts:196–236  ·  view source on GitHub ↗
(node: SDK.DOMModel.DOMNode, optimized?: boolean)

Source from the content-addressed store, hash-verified

194};
195
196const xPathValue = function(node: SDK.DOMModel.DOMNode, optimized?: boolean): Step|null {
197 let ownValue;
198 const ownIndex = xPathIndex(node);
199 if (ownIndex === -1) {
200 return null;
201 } // Error.
202
203 switch (node.nodeType()) {
204 case Node.ELEMENT_NODE:
205 if (optimized && node.getAttribute('id')) {
206 return new Step('//*[@id="' + node.getAttribute('id') + '"]', true);
207 }
208 ownValue = node.localName();
209 break;
210 case Node.ATTRIBUTE_NODE:
211 ownValue = '@' + node.nodeName();
212 break;
213 case Node.TEXT_NODE:
214 case Node.CDATA_SECTION_NODE:
215 ownValue = 'text()';
216 break;
217 case Node.PROCESSING_INSTRUCTION_NODE:
218 ownValue = 'processing-instruction()';
219 break;
220 case Node.COMMENT_NODE:
221 ownValue = 'comment()';
222 break;
223 case Node.DOCUMENT_NODE:
224 ownValue = '';
225 break;
226 default:
227 ownValue = '';
228 break;
229 }
230
231 if (ownIndex > 0) {
232 ownValue += '[' + ownIndex + ']';
233 }
234
235 return new Step(ownValue, node.nodeType() === Node.DOCUMENT_NODE);
236};
237
238const xPathIndex = function(node: SDK.DOMModel.DOMNode): number {
239 /**

Callers 1

xPathFunction · 0.85

Calls 5

xPathIndexFunction · 0.85
nodeTypeMethod · 0.80
localNameMethod · 0.80
nodeNameMethod · 0.80
getAttributeMethod · 0.45

Tested by

no test coverage detected