一、非uiautomator
- resource-id
driver.find_element_by_id(id)
- class
driver.find_element_by_class(class)
- text(实际上是xpath)
xpath = "//android.widget.TextView[@text='中国']"
element = driver.find_element_by_xpath(xpath)
- xpath
xpath = "//android.widget.TextView[@text='登录']"
element = driver.find_element_by_xpath(xpath)
- content-desc
driver.find_element_by_android_uiautomator('new UiSelector().description("立即注册")')
二、uiautomator
- resourceId
driver.find_element_by_android_uiautomator('new UiSelector().resourceId("%s")')
- text
driver.find_element_by_android_uiautomator('new UiSelector().text("%s")')
- description
driver.find_element_by_android_uiautomator('new UiSelector().description("%s")')
- className
driver.find_element_by_android_uiautomator('new UiSelector().className("%s")')
- index
driver.find_element_by_android_uiautomator('new UiSelector().index("%s")')
- className + index
driver.find_element_by_android_uiautomator(
'new UiSelector().className("%s").childSelector(new UiSelector().index("%d"))')
- 伪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()