MCPcopy Index your code
hub / github.com/callstack/agent-device / buildSelectorChainForNode

Function buildSelectorChainForNode

src/utils/selector-build.ts:6–67  ·  view source on GitHub ↗
(
  node: SnapshotNode,
  _platform: Platform | PublicPlatform,
  options: { action?: 'click' | 'fill' | 'get' } = {},
)

Source from the content-addressed store, hash-verified

4import { extractNodeText, normalizeType } from '../snapshot/snapshot-processing.ts';
5
6export function buildSelectorChainForNode(
7 node: SnapshotNode,
8 _platform: Platform | PublicPlatform,
9 options: { action?: 'click' | 'fill' | 'get' } = {},
10): string[] {
11 const chain: string[] = [];
12 const role = normalizeType(node.type ?? '');
13 const id = normalizeSelectorText(node.identifier);
14 const label = normalizeSelectorText(node.label);
15 const value = normalizeSelectorText(node.value);
16 const text = normalizeSelectorText(extractNodeText(node));
17 const requireEditable = options.action === 'fill';
18
19 if (id) {
20 chain.push(`id=${quoteSelectorValue(id)}`);
21 }
22 if (role && label) {
23 chain.push(
24 requireEditable
25 ? `role=${quoteSelectorValue(role)} label=${quoteSelectorValue(label)} editable=true`
26 : `role=${quoteSelectorValue(role)} label=${quoteSelectorValue(label)}`,
27 );
28 }
29 if (label) {
30 chain.push(
31 requireEditable
32 ? `label=${quoteSelectorValue(label)} editable=true`
33 : `label=${quoteSelectorValue(label)}`,
34 );
35 }
36 if (value) {
37 chain.push(
38 requireEditable
39 ? `value=${quoteSelectorValue(value)} editable=true`
40 : `value=${quoteSelectorValue(value)}`,
41 );
42 }
43 if (text && text !== label && text !== value) {
44 chain.push(
45 requireEditable
46 ? `text=${quoteSelectorValue(text)} editable=true`
47 : `text=${quoteSelectorValue(text)}`,
48 );
49 }
50 if (role && requireEditable && !chain.some((entry) => entry.includes('editable=true'))) {
51 chain.push(`role=${quoteSelectorValue(role)} editable=true`);
52 }
53
54 const deduped = uniqueStrings(chain);
55 if (deduped.length === 0 && role) {
56 deduped.push(
57 requireEditable
58 ? `role=${quoteSelectorValue(role)} editable=true`
59 : `role=${quoteSelectorValue(role)}`,
60 );
61 }
62 if (deduped.length === 0) {
63 const visible = isNodeVisible(node);

Callers 5

getCommandFunction · 0.90
healReplayActionFunction · 0.90

Calls 7

normalizeTypeFunction · 0.90
extractNodeTextFunction · 0.90
isNodeVisibleFunction · 0.90
normalizeSelectorTextFunction · 0.85
quoteSelectorValueFunction · 0.85
pushMethod · 0.80
uniqueStringsFunction · 0.70

Tested by 1