Appium定位方式总结

经过appium-desktop定位元素html

 

 

 

ClassNameandroid

Androidios

Android的class属性对应ClassName定位方式,ClassName通常都是会重复的,能够经过index来获取须要的元素。(从0开始查找dom树中的同名class属性)app

iOS框架

iOS的type属性对应CLassName定位方式,ClassName通常都是会重复的,能够经过index来获取须要的元素。(从0开始查找dom树中的同名class属性)dom

 

ID测试

Androidui

Android的resource-id对应ID定位方式,这个id也可能存在重复状况,能够经过index来获取须要的元素。(从0开始查找dom树中的同名resource-id属性)spa

使用appium-desktop来获取元素时,若是提示有id的定位方式,则能够只接获取,表明惟一。code

 

XPATH

Android

Android的Xpath定位与PC的XPATH定位大同小异,能够经过相对路径的定位方式定位,区别在于,这里相对路径定位的//后只能够接Android的class属性或*。(//android.widget.Button[@text="登 录"])

iOS

iOS10 以上使用XCUITest框架后,原生框架不支持XPATH,Appium进行了转换,速度很慢不建议使用。

 

AccessibilityId

Android

Android的content-desc属性对应AccessibilityId定位方式,这个content-desc属性专门为残障人士设置,若是这个属性不为空则推荐使用。

iOS

iOS的label和name属性都对应AccessibilityId定位方式,若是有则推荐使用。

 

AndroidUIAutomator

Android的源生测试框架的定位方式,定位速度快。推荐使用牢记经常使用的几种。

打开方法:

 

# 这个在运行时,调用的是Android自带的UI框架UiAutomator的Api # 介绍几个简单经常使用的,text、className、resource-id # text # 匹配所有text文字
driver.find_element_by_android_uiautomator('new UiSelector().text("手机号")') # 包含text文字
driver.find_element_by_android_uiautomator('new UiSelector().textContains("机")') # 以text什么开始
driver.find_element_by_android_uiautomator('new UiSelector().textStartsWith("手")') # 正则匹配text
driver.find_element_by_android_uiautomator('new UiSelector().textMatches("^手.*")') # className
driver.find_elements_by_android_uiautomator('new UiSelector().className("android.widget.TextView")') # classNameMatches
driver.find_elements_by_android_uiautomator('new UiSelector().classNameMatches("^android.widget.*")') # resource-id、resourceIdMatches 相似咱们html id 这个可能重复,
 driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.syqy.wecash:id/et_content")') # description driver.find_element_by_android_uiautomator('new UiSelector().description("S 日历")') # descriptionStartsWith driver.find_element_by_android_uiautomator('new UiSelector().descriptionStartsWith("日历")') # descriptionMatches driver.find_element_by_android_uiautomator('new UiSelector().descriptionMatches(".*历$")'

iOSPredicateString

仅支持iOS10以上,能够多个属性同时定位,推荐。(替代XPATH)

driver.find_elements_by_ios_predicate("label == '登陆'") driver.find_elements_by_ios_predicate("type='XCUIElementTypeOther' and name='联系人,标签, 第2个按钮,共3个'")

iOSUIAutomation

iOS9.3如下使用,如今已经废弃,iOSPredicateString代替了iOSUIAutomation

相关文章
相关标签/搜索