Robot Framework 元素定位(3-1)

RobotFramework - AppiumLibrary 之元素定位
一、介绍
AppiumLibrary 是 Robot Framework 的App测试库。

它使用Appium 与Android 和 iOS应用程序进行通信,类似于Selenium WebDriver与Web浏览器的对话。

AppiumLibrary是继承和引用appiumandroidlibrary,但重新实现使用appium 1.X技术,它完全支持Python 2.7,但对python 3.3+的支持仍然是实验性的。

二、定位控件
AppiumLibrary需要在应用程序中查找元素的所有关键字都使用参数locator。

当提供locator值时,它将与特定元素类型的键属性进行匹配。支持的定位器(locator)有:
Robot Framework 元素定位(3-1)

三、定位元素

1. identifier 定位

说明:匹配 @id 或 @name 属性,分别对应 resource-id 和 text 属性。

案例:点击计算器数字“ 9 ”,可以使用id定位,也可以使用name定位。

Robot Framework 元素定位(3-1)

2. id 定位

说明:匹配 @id 属性,对应 resource-id 属性。

案例:点击计算器输入框,id可以指定也可以不指定,如果不指定策略,默认就是id定位。
Robot Framework 元素定位(3-1)

3. name 定位

说明:匹配 @name 属性,对应 text 属性。

案例:点击计算器数字“ 9 ”。

Robot Framework 元素定位(3-1)

4. xpath 定位

说明:匹配 Xpath ,这也是功能最强大的一种定位方式,不过通常用于web自动化。

案例:点击计算器数字“ 7 ”。

Robot Framework 元素定位(3-1)
附加Xpath定位表达式说明:

Robot Framework 元素定位(3-1)

5. class 定位

说明:匹配 class name ,对应 class 属性,但通常class属性都不唯一。

案例:点击计算器数字“ 6 ”。

Robot Framework 元素定位(3-1)

6. accessibility_id 定位

说明:匹配 辅助选项,这个方法属于Appium扩展的定位方法,主要就是content-desc属性。

案例:点击计算器加号“ + ”。
Robot Framework 元素定位(3-1)

7. android 定位

说明:匹配 Android UI Automator。

案例:点击计算器加号“ + ”。
Robot Framework 元素定位(3-1)

8. css 定位

说明:匹配 css in webview,只适用于webview的html页面,继承自webdriver。

9. ios 定位

说明:匹配 iOS UI Automation,很显然只适用于ios系统。