MCPcopy Create free account
hub / github.com/appium/appium / runQuery

Function runQuery

packages/universal-xml-plugin/lib/xpath.ts:14–31  ·  view source on GitHub ↗
(query: string, xmlStr: string)

Source from the content-addressed store, hash-verified

12 * @param xmlStr XML source.
13 */
14export function runQuery(query: string, xmlStr: string): Element[] {
15 const dom = new DOMParser().parseFromString(xmlStr, MIME_TYPE.XML_TEXT);
16 let nodes: ReturnType<typeof xpathQuery>;
17 try {
18 // @ts-expect-error Missing Node properties are not needed.
19 // https://github.com/xmldom/xmldom/issues/724
20 nodes = xpathQuery(query, dom);
21 } catch (err) {
22 // report a malformed query the same way drivers do instead of as an unknown server error.
23 // messages such as 'Unknown function foo' tell the user what to fix, the generic one does not
24 const reason = (err as Error).message;
25 const details = reason && reason !== GENERIC_XPATH_PARSE_ERROR ? ` (${reason})` : '';
26 throw new errors.InvalidSelectorError(`Invalid XPath selector: ${query}${details}`, err as Error);
27 }
28 // the xpath typings describe lib.dom nodes rather than xmldom ones, so this is the one place
29 // where the two type worlds have to be bridged
30 return nodes as unknown as Element[];
31}
32
33/**
34 * Transforms an XPath query to work with the original platform-specific XML

Callers 3

transformQueryFunction · 0.85
xpath.spec.tsFile · 0.85
plugin.spec.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected