uiautomator
uiautomator方法定位app元素:
appium在android端是调用其底层的UIAutomator2自动化测试框架去驱动自
动化,在定位元素的时候,可以借助UIAutomator2的语法来实现定位。在代码
实现上提供的API是find_element_by_android_uiautomator。
1、根据text定位:
find_element_by_android_uiautomator('text("值")')
find_element_by_android_uiautomator('new UiSelector().text("值")')
text定位相关函数:
textContains:模糊匹配文本
textStartsWith:以某个文本开头来匹配
textMatches:正则匹配
uiautomator方法定位app元素:
2、根据resourceId定位:
find_element_by_android_uiautomator('resourceId("值")')
find_element_by_android_uiautomator('new UiSelector().resourceId("值")')
3、根据className定位: 关键字 className
4、根据contenet-des定位: 关键字 description
5、组合定位(类名和文本):
new UiSelector().className("类名").text("值")
其它组合定位方式类推
uiautomator方法定位app元素:
6、根据元素关系定位:
1)后代元素定位
使用条件:子元素属性不定,不唯一,只能通过父元素来定位
new UiSelector().resourceId("值").childSelector(className("值").instance(数字))
其中childSelector可以传入resourceId、description等方法
instance表示匹配的结果所有元素里面的第几个元素,从0开始计数
2)兄弟元素定位
通过子元素找到父元素,然后通过父元素再去找兄弟元素
new UiSelector().resourceId("值").fromParent(text("值"))
fromParent()表示从元素的父元素下查找
回忆滋润坚持
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步