標籤:
text屬性的方法
driver.find_element_by_android_uiautomator(‘new UiSelector().text("Custom View")‘).click() #textdriver.find_element_by_android_uiautomator(‘new UiSelector().textContains("View")‘).click() #textContainsdriver.find_element_by_android_uiautomator(‘new UiSelector().textStartsWith("Custom")‘).click() #textStartsWithdriver.find_element_by_android_uiautomator(‘new UiSelector().textMatches("^Custom.*")‘).click() #textMatches
class屬性的方法
driver.find_element_by_android_uiautomator(‘new UiSelector().className("android.widget.TextView").text("Custom View")‘).click() #classNamedriver.find_element_by_android_uiautomator(‘new UiSelector().classNameMatches(".*TextView$").text("Custom View")‘).click() #classNameMatches
偽xpath方法定位
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(new UiSelector().text("Custom View"))‘).click() #通過父級元素定位子集元素
resourceId屬性的方法
driver.find_element_by_android_uiautomator(‘new UiSelector().resourceId("android:id/text1")‘) #resourceIddriver.find_element_by_android_uiautomator(‘new UiSelector().resourceIdMatches(".*id/text1$")‘) #resourceIdMatches
description屬性的方法
driver.find_element_by_android_uiautomator(‘new UiSelector().description("Custom View")‘).click() #descriptiondriver.find_element_by_android_uiautomator(‘new UiSelector().descriptionStartsWith("Custom")‘).click() #descriptionStartsWithdriver.find_element_by_android_uiautomator(‘new UiSelector().descriptionMatches("^Custom.*")‘).click() #descriptionMatches
元素的其他屬性
除了以上比較常用的方法外,UIAutomator還支援其他一些方法,比如根據控制項屬性是否可點擊可聚焦可長按等來縮小要定位的控制項的範圍,具體使用方法不一一列舉(checked,clickable,focesed.......)
driver.find_element_by_android_uiautomator(‘new UiSelector().clickable(true).text("Custom View")‘).click()
【appium】根據UIAutomator定位元素