FindNode 示例

Action 中的查询 - I

最基本的查询是“{}”或在 TC 中:

var output = device.sendAai({})

这将返回屏幕上的大多数节点,默认返回是节点 ID 列表(操作:“getIds”):

{count: 89, ids: ['80006cbe','7440','7bc2','7f83','8344','8705','8ac6','8e87','1f6e7',…]}

您可以执行以下操作:

{query:“CC:!=0”} 或 {query:”CC:>0}:非零子计数。

{query:”IT:>10000”},接受大于10000的自定义输入类型值。

{query:"CC:!=0&&IT:>10000"},查找子节点非零且输入类型大于 10,000 的节点。

{query:”TP:textInput&&IX:2”, action:”setText(Hello)”},找到第三个文本字段并在文本字段中输入“Hello”。

{query:”T:Input text here”, action:”setText(Hello)”},找到空文本字段有初始提示文本,搜索提示并输入“Hello”。

{query:”C:.TextView&&T: Contacts"}
>> device.sendAai({query:"T:*REAL, \nSANTA CLARA*", action:"getText"})
{retval: '3367 EL CAMINO REAL, 
SANTA CLARA, CA 95051'}
>> device.sendAai({actions:["scrollIntoView(T:ci:john)", "click"]})

Action 中的查询 - II

示例 1:在屏幕底部查找节点:

>> device.sendAai({query:"LB:-1", action:"getText"})
{retval: ['Chats','Calls','Contacts','Notifications']}

通过使用偏移量 (OX)、索引 (IX) 或“T:”等查询,您几乎可以定位上述示例中的每个节点,点击“联系人”图标以下 3 个示例:

>> device.sendAai({query:"LB:1&&IX:2", action:"click"})
{retval: true}
>> device.sendAai({query:"LB:-1&&T:Contacts&&OY:-1", action:"click"})
{retval: true}
>> device.sendAai({query:"LB:-1", action:"click(T:Contacts&&OY:-1)"})
{retval: true}

行模式的目的是控制顶部/底部的图标。与聊天图标相交的红色计数器将被删除。所以对于图标行,它是 4 个节点而不是 5 个节点:

>> device.sendAai({query:"LB:1"})
{count: 4, ids: ['14735','17080','18ac7','1a50e']}

如果您想要计数器,请使用其他查询(IX:-1 或 ON:last 可用于防止在屏幕上找到其他“聊天”,选择最后一个“聊天”),下面的第二行将起作用,因为偏移量不会忽略相交的节点:

>> device.sendAai({query:"T:Chats&&IX:-1&&OY:-1&&OX:1", action:"getText"})
{retval: '1'}
>> device.sendAai({query:"LB:-1&&T:Chats&&OY:-1&&OX:1", action:"getText"})
{retval: '1'}

示例 2:从 About 电话中检索信息:

获取信息:

>> device.sendAai({query:"T:Model name&&OX:1", action:"getText"})
{retval: 'Galaxy S10+'}

或者,您可以使用 UiElement 类:

>> var obj = UiElement.findObject(device, "T:Model name&&OX:1")
UiElement: 3d012
>> obj.getText()
Galaxy S10+

示例 3:假设您想从 Yahoo Finance 获取股票代码的首页:

>> device.sendAai({query:"R:.ticker&&T:/[A-Z]{1,4}/", action:"getText"}).retval.forEach(
 (p) => {print( p + ":" +
   device.sendAai({action:"getDescription(OX:1&&T:" + p + ")"}).retval
   )
  }
 )
TGT:164.76
T:16.76
AAPL:154.48
SBUX:92.14
TSLA:309.07
CSCO:43.30

示例 4:在 Skype 文本框中输入文本:

输入文字前:

文字输入后,需要点击按钮发送:

这可以通过在一个查询命令中使用来完成:

>> var input = "Hello";
>> device.sendAai({query:"LB:1&&TP:textInput", actions:[aaix("setText", input), "click(OX:2)"]});
{count: 2, list: [{retval: true},{retval: true}]}

aaix("setText", input) 将返回 'setText("Hello")',比 'setText("'+input+'")' 好得多,对多个参数有用。

以下功能查找人员,单击,发送消息并返回主页面。

function sendAai(device, obj) {
 var retval = device.sendAai(obj);
 if (retval == null) {
  throw "Error on: " + JSON.stringify(obj) + ":" + lastError();
 }
 print("$ " + JSON.stringify(obj) + "\n" + JSON.stringify(retval));
 return retval;
}

function sendSkype(device, name, text) {
 sendAai(device, {actions:[
  aaix("scrollIntoView", "T:" + name), 
  "click", 
  "newQuery(TP:textInput)", 
  aaix("setText", text), 
  "click(OX:2)", 
  "waitQuery(T:Type a message)",
  "sendKey(Back)"
 ]})
}

sendSkype(device, "John", "I will get back to you");

示例 5:在第一个示例中,您可以使用“T:<text>”和偏移量来单击图标,某些应用程序不提供文本:

由于这是显示在最后一行,我们可以使用“LB:-1”返回节点,然后使用“IX”从节点列表中定位单个节点,点击搜索图标:

device.sendAai({query:"LB:-1&&IX:2", action:"click"})

示例 6:在某个聊天窗口中,它显示了姓名(或电话号码),要获取它,请使用以下查询:

>> device.sendAai({query:"LT:1&&IX:1", action:"getText"})
{retval: (999)999-9999}

要返回,请单击左箭头:

>> device.sendAai({query:"LT:1&&IX:0", action:"click"})
{retval: true}

注意:新版本的“Messages”、“LT”和“LB”不再起作用,仍然可以检索第一行或最后一行信息,使用“VG”获取组信息,使用“RN”还原到感兴趣的节点..

第一行:

>> device.sendAai({query:"TP:reduced&&IX:0&&VG&&RN"})
{count: 6, ids: ['1669cf','168f59','16931a','1696db','169a9c','167151']}

最后一行:

>> device.sendAai({query:"TP:reduced&&IX:-1&&VG&&RN"})
{count: 5, ids: ['16227c','162dbf','15db29','15deea','16570a']}

收到节点后,可以使用 addQuery() 选择节点或执行操作。

示例 7:轻松找到并单击。

要单击箭头,请使用:

>> device.sendAai({query:"T:Channels&&OX:1", action:"click"})
{retval: true}

Action 中的查询 - III

示例 1:考虑以下杂货店应用程序:

要将橙子添加到购物车中,“scrollIntoView”将滚动直到找到“*Orange*”并将“Valencia Oranges ...”节点存储在ML中,VG&&RN将获取ViewGroup并优化节点数。使用 UI Explorer 找出价格的资源 ID,并使用“+”按钮保存到购物车。

>> device.sendAai({actions:[
 "scrollIntoView(T:*Oranges*)", 
 "addQuery(VG&&RN)", 
 "getText(R:.tv_price)", 
 "click(R:/.iv_edit_right|.iv_num/)"
]})
{count: 4, list: [{retval: true},{count: 8},{retval: '$6.99'},{retval: true}]}

示例 2:使用“选中”来操作复选框。

要扩展,需要使用来匹配不同类型的空白:

>> device.sendAai({query:"T:/3:00\\sAM/&&OX:1", action:"click"})
{retval: true}

要将今天旁边的复选框从true更改为false,请使用“checked”,仍然需要使用“3:00 AM”,因为屏幕上可能还有其他带有“Today”的警报。

>> device.sendAai({query:"T:/3:00\\sAM/&&OY:1&&OX:1", actions:["getChecked", "setChecked(false)", "getChecked"]})
{count: 3, list: [{retval: true},{changedCount: 1},{retval: false}]}

对于周期性闹钟,例如从周日到周六,它使用“D:Sunday”和“T:S”来表示第一个复选框。使用 intersectX (TX) 获取所有复选框。在此示例中,不需要“C:.CheckBox”,但可以作为示例使用:

>> device.sendAai({action:"getDescription(D:Sunday&&C:.CheckBox&&TX)"})
{retval: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']}

要检查所有复选框,setChecked 不支持查询,它返回已更改的数量。

>> device.sendAai({query:"D:Sunday&&C:.CheckBox&&TX", action:"setChecked(true)"})
{changedCount: 7}

有几种方法可以关闭周日和周六:

>> device.sendAai({query:"D:/Sunday|Saturday/", action:"setChecked(false)"})
{changedCount: 2}
>> device.sendAai({query:"T:S", action:"setChecked(false)"})
{changedCount: 2}

To obtain the value of these checkboxes:
>> device.sendAai({query:"D:Sunday&&C:.CheckBox&&TX", action:"getChecked"})
{retval: [false,true,true,true,true,true,false]}

示例 3:OY 和 OX 的顺序很重要,以下是开发人员选项之一:

“禁用 adb 授权超时”右侧没有节点,因此在 X 上应用偏移量将变为空:

>> device.sendAai({query:"T:Disable adb authorization*&&OX:1&&OY:1"})
null
>> lastError()
Offset out of range

如果“OX”和“OY”的顺序颠倒,它将起作用,它在 X 之前在 Y 上应用偏移量,将得到正确的节点:

>> device.sendAai({query:"T:Disable adb authorization*&&OY:1&&OX:1"})
{count: 1, ids: ['25c8d4']}
>> device.sendAai({query:"T:Disable adb authorization*&&OY:1&&OX:1", action:"getChecked"})
{retval: false}
>> device.sendAai({query:"T:Disable adb authorization*&&OY:1&&OX:1", actions:["setChecked(true)", "getChecked"]})
{count: 2, list: [{changedCount: 1},{retval: true}]}

把所有东西放在一起,使用“openAndroidSetting”打开开发者选项:

>> device.sendAai({actions:[
 "openAndroidSetting(APPLICATION_DEVELOPMENT_SETTINGS)",
 "scrollIntoView(T:Disable adb authorization*)",
 "addQuery(OY:1&&OX:1)",
 "setChecked(true)",
 "sendKey(Back)"
]})
{count: 5, list: [{retval: true},{retval: true},{count: 1},{changedCount: 1},{retval: true}]}

例4:将开发者选项“窗口动画比例”改为“2x”,需要用“+”改为T:*2x,因为是新窗口,需要新查询。

>> device.sendAai({actions:[
 "openAndroidSetting(APPLICATION_DEVELOPMENT_SETTINGS)",
 "scrollIntoView(T:Window animation scale)",
 "click", 
 "click(+T:*2x)", 
 "sendKey(back)"
]})
{count: 5, list: [{retval: true},{retval: true},{retval: true},{retval: true},{retval: true}]}