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 无提示
滚动查找元素:
from appium.webdriver.common.mobileby import MobileBy
def 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()
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。