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

Function validateXPath

util/dom_utils.js:52–72  ·  view source on GitHub ↗
(xpath)

Source from the content-addressed store, hash-verified

50 * Validate XPath syntax and check if it finds elements
51 */
52export function validateXPath(xpath) {
53 try {
54 const result = document.evaluate(xpath, document, null, XPathResult.ANY_TYPE, null);
55 let count = 0;
56 let node = result.iterateNext();
57 while (node) {
58 count++;
59 node = result.iterateNext();
60 }
61 return {
62 valid: true,
63 count: count,
64 isUnique: count === 1
65 };
66 } catch (e) {
67 return {
68 valid: false,
69 error: e.message
70 };
71 }
72}
73
74/**
75 * Get element value handling different input types

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected