FindNode Actions & Commands
Actions are performed on nodes matched by queries. Chain multiple actions with semicolons.
Common Actions
| Action | Description | Example |
|---|---|---|
click | Click matched element | action: "click" |
longClick | Long-press element | action: "longClick" |
setText(text) | Enter text into field | action: "setText(Hello)" |
getText | Get element's text | action: "getText" |
getIds | Get element IDs | action: "getIds" |
getBounds | Get element position | action: "getBounds" |
getNodes(prop) | Get nodes with property | action: "getNodes(T)" |
setChecked(bool) | Check/uncheck | action: "setChecked(true)" |
Navigation Actions
| Action | Description |
|---|---|
scrollIntoView(query, dir, pages) | Scroll until element found |
openApp(package) | Open app by package name |
openAndroidSetting(setting) | Open Android settings page |
clickForNewWindow(query) | Click and wait for new window |
sendKey(key) | Send keyboard key (Back, Home, Enter) |
refreshQuery | Re-run query on updated screen |
Query Management Actions
| Action | Description |
|---|---|
newQuery(query) | Start a new query from current context |
addQuery(query) | Add conditions to current query |
waitQuery(query) | Wait for element to appear |
refresh(query) | Refresh with new query |
Chaining Actions
Use semicolons to chain multiple actions:
javascript
// Open app, scroll to find element, click it
device.sendAai({
action: "openApp(com.example.app);scrollIntoView(T:Settings);click"
});
// Get Android version
device.sendAai({
action: `openAndroidSetting(DEVICE_INFO_SETTINGS);
click(T:Software information);
refreshQuery;
getText('T:Android version&&OY:1')`
});
// Returns: { count: 4, list: [{retval: true},{retval: true},{retval: true},{retval: '16'}] }Using Action Arrays
For complex sequences, use the actions array:
javascript
device.sendAai({
actions: [\
"scrollIntoView(T:john)",\
"click",\
"newQuery(TP:textInput)",\
"setText('Hello')",\
"click(OX:2)",\
"sendKey(Back)"\
]
});Element-Based Actions
Target specific elements by ID using elements array:
javascript
// Click elements in sequence
device.sendAai({
elements: [id1, id2, id3],
action: "forEach(nsClick);sleep(500)"
});Variables in Queries
Use template literals for dynamic values:
javascript
var input = "Hello World";
device.sendAai({
query: "TP:textInput",
actions: [`setText('${input}')`, "click(OX:2)"]
});Action Return Values
Actions return structured objects:
javascript
// Single action
{ retval: true } // click success
{ retval: "Button text" } // getText result
{ count: 5, ids: [...] } // getIds result
// Chained actions
{ count: 3, list: [\
{ retval: true }, // action 1 result\
{ retval: true }, // action 2 result\
{ retval: "16" } // action 3 result\
]}