UIAutomator API定位元素

允我心安 提交于 2019-12-11 02:39:18

一、根据class name和text属性  包名不可省略

  code= new UiSelector().text("我的").classname("android.widget.TextView")

  driver.find_element_by_android_uiautomator(code)

  driver.find_elements_by_android_uiautomator(code)

 

二、根据resource id属性  包名不可省略

  new UiSelector().resourceId("com.ibox.calculators:id/account_txt")

三、childSelector  相当于//

  这种方法是在已知父控件的时候如何快速的查找该父控件下面的子控件。

四、instance  index  用于子元素

  index   Set the search criteria to match the widget by its node index in the layout hierarchy.

     设置查询标准根据布局结构中的节点index匹配部件

       多多计算器 ,查询数字元素,查询数字元素每行的第三个元素

       new UiSelector().textMatches("[0-9]").index(2) 结果为3/6/9,结果为每一行的第三个元素

  instance Set the search criteria to match the widget by its instance number

     设置查询标准(条件)根据编号匹配部件

        多多计算器 ,查询数字元素   查询CV的className为TextView的第二个子元素

        new UiSelector().resourceId("com.ibox.calculators:id/cv").childSelector(new UiSelector().className("android.widget.TextView").instance(1))   

 

五、fromParent 根据元素的父元素找到兄弟元素

      多多计算器 ,查询数字3,根据父元素查找数字1 ,两个元素为(非)兄弟元素,即有相同一个父元素  

      new UiSelector().text("3").fromParent(new UiSelector().text("1"))

 

UiSelector的官方帮助文档

https://developer.android.google.cn/topic/libraries/testing-support-library/index.html#UIAutomator

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!