标签:selector tco appium sed 包含 定位元素 family str art
|
1
2
3
4
|
driver.find_element_by_android_uiautomator(‘new UiSelector().text("字节跳动公司")‘).click() #text 精准定位全文driver.find_element_by_android_uiautomator(‘new UiSelector().textContains("字节")‘).click() 包含text文字driver.find_element_by_android_uiautomator(‘new UiSelector().textStartsWith("字")‘).click() #textStartsWith 以text什么开始driver.find_element_by_android_uiautomator(‘new UiSelector().textMatches("^字节.*")‘).click() #textMatches 正则匹配text |
class属性的方法
|
1
2
|
#className
driver.find_element_by_android_uiautomator(‘new UiSelector().className("android.widget.TextView").text("Custom View")‘).click() #classNameMatches
driver.find_element_by_android_uiautomator(‘new UiSelector().classNameMatches(".*TextView$").text("CustomView")‘).click() |
伪xpath方法定位
|
1
2
|
#通过同级元素定位同级元素
driver.find_element_by_android_uiautomator(‘new UiSelector().text("Custom View").fromParent(new UiSelector().text("Accessibility Service"))‘).click() #通过父级元素定位子集元素
driver.find_element_by_android_uiautomator(‘new UiSelector().className("android.widget.ListView").childSelector(newUiSelector().text("Custom View"))‘).click() |
resourceId属性的方法
|
1
2
|
#resourceId
driver.find_element_by_android_uiautomator(‘new UiSelector().resourceId("android:id/text1")‘)#resourceIdMatches
driver.find_element_by_android_uiautomator(‘new UiSelector().resourceIdMatches(".*id/text1$")‘) |
|
1
2
3
|
#description
driver.find_element_by_android_uiautomator(‘new UiSelector().description("Custom View")‘).click()#descriptionStartsWith
driver.find_element_by_android_uiautomator(‘new UiSelector().descriptionStartsWith("Custom")‘).click()#descriptionMatches
driver.find_element_by_android_uiautomator(‘new UiSelector().descriptionMatches("^Custom.*")‘).click() |
元素的其他属性
除了以上比较常用的方法外,UIAutomator还支持其他一些方法,比如根据控件属性是否可点击可聚焦可长按等来缩小要定位的控件的范围,具体使用方法不一一列举(checked,clickable,focesed.......)
|
1
|
driver.find_element_by_android_uiautomator(‘new UiSelector().clickable(true).text("Custom View")‘).click() |
【自动化APP】--appium 之UIAutomator 框架定位元素
标签:selector tco appium sed 包含 定位元素 family str art
原文地址:https://www.cnblogs.com/hlwa/p/14122479.html