03-05 APP自动化测试-常用定位方式
Posted Leofighting
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了03-05 APP自动化测试-常用定位方式相关的知识,希望对你有一定的参考价值。
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 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()
以上是关于03-05 APP自动化测试-常用定位方式的主要内容,如果未能解决你的问题,请参考以下文章
app自动化测试----基础入门appium初使用2(Uiautomator 元素定位)