UIAutomator API定位元素
一、根据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
最新文章
- SQL 事务隔离学习
- 常用数据库高可用和分区解决方案(1) — MySQL篇
- STL_fill()用法
- sql server中sql语句中单引号怎么转义?【转】
- web前端开发工程师,你了解吗?
- VS2012添加PlaySound引用
- 解决Gradle DSL method not found: ‘android()’
- 嵌入式 uboot以及kernel添加看门狗临时记录(个人记录未整理乱)
- Android Cursor空指针的问题
- nginx处理静态资源的配置
- JavaScript的DOM编程--12--innerHTML属性
- Java集合中的Map接口
- c# 工具类(字符串和时间,文件)
- nginx nfs服务
- Struts,Spring,Hibernate三大框架的
- Ansys热应力计算
- POIUtils 导出 poi Test 100w 600w 条数据
- MVC 获取控制器名称和Action名称(转载)
- 在html中控制自动换行
- 标准库string的用法探讨