id 定位
dirver.find_element_by_id(resource-id 属性值)driver.find_element_by(MobileBy.ID, resource-id 属性值)
accessibility_id 定位
driver.find_element_by_accessibility_id(content-desc 属性值)driver.find_element_by(MobileBy.ACCESSIBILITY_ID, content-desc 属性值)
xpath 定位
driver.find_element_by_xpath(xpath 属性值)
当遇到无奈惟一定位的状况,倡议应用 xpath 的组合定位
uiautomator 定位
长处:
- uiautomator 是 Android 的工作引擎,比 xpath 定位速度快
毛病:
- 表达式书写简单,容易写错,IDE 无提醒
Uiautomator--Uiselector元素定位
滚动查找元素:
from appium.webdriver.common.mobileby import MobileBydef find_by_scroll(self): self.driver.find_element( MobileBy.ANDROID_UIAUTOMATOR, 'new UiScrollable(new UiSelector().' 'scrollable(true).instance(0)).' 'scrollIntoView(new UiSelector().' 'text("想要查到的文本").' # 批改想要查找的文本信息即可 'instance(0));').click()