標籤:cas 總結 ppi selector 速度 dex 號碼 label ios
1、ID
Android
Android的resource-id對應ID定位方式,可以通過index來擷取需要的元素(從0開始尋找dom樹中的同名resource-id屬性)。使用appium-desktop來擷取元素時,id和resource-id是相同的,如果只有resource-id,可能存在重複現象,如果提示有id的定位方式,則可以只接擷取,代表唯一。
driver.find_element_by_id(‘com.tencent.mobileqq:id/btn_login‘)
2、AccessibilityId
Android
Android的content-desc屬性對應AccessibilityId定位方式,這個content-desc屬性專門為殘障人士設定,如果這個屬性不為空白則推薦使用。
driver.find_element_by_accessibility_id(‘請輸入QQ號碼或手機或郵箱‘)
iOS
iOS的label和name屬性都對應AccessibilityId定位方式,如果有則推薦使用。
3、Xpath
Android
Android的Xpath定位與PC的Xpath定位大同小異,可以通過相對路徑的定位方式定位。區別在於,這裡相對路徑定位的//後只可以接Android的class屬性或*。
driver.find_element_by_xpath(‘//android.widget.EditText[@text="QQ號/手機號/郵箱"]‘)
iOS
iOS10 以上使用XCUITest架構後,原生架構不支援XPATH,Appium進行了轉換,速度很慢不建議使用。
4、UIAutomator
Android的源生測試架構的定位方式,定位速度快。推薦使用常用的幾種。
1 # 這個在運行時,調用的是Android內建的UI架構UiAutomator的Api 2 # 介紹幾個簡單常用的,text、className、resource-id 3 # text 4 # 匹配全部text文字 5 driver.find_element_by_android_uiautomator(‘new UiSelector().text("手機號")‘) 6 # 包含text文字 7 driver.find_element_by_android_uiautomator(‘new UiSelector().textContains("機")‘) 8 # 以text什麼開始 9 driver.find_element_by_android_uiautomator(‘new UiSelector().textStartsWith("手")‘)10 # 正則匹配text11 driver.find_element_by_android_uiautomator(‘new UiSelector().textMatches("^手.*")‘)12 13 # className14 driver.find_elements_by_android_uiautomator(‘new UiSelector().className("android.widget.TextView")‘)15 # classNameMatches16 driver.find_elements_by_android_uiautomator(‘new UiSelector().classNameMatches("^android.widget.*")‘)17 18 # resource-id、resourceIdMatches19 driver.find_element_by_android_uiautomator(‘new UiSelector().resourceId("com.syqy.wecash:id/et_content")‘)20 21 # description22 driver.find_element_by_android_uiautomator(‘new UiSelector().description("S 日曆")‘)23 # descriptionStartsWith24 driver.find_element_by_android_uiautomator(‘new UiSelector().descriptionStartsWith("日曆")‘)25 # descriptionMatches26 driver.find_element_by_android_uiautomator(‘new UiSelector().descriptionMatches(".*曆$")‘)
5、iOSPredicateString
僅支援iOS10以上,可以多個屬性同時定位,推薦。(替代XPATH)
driver.find_elements_by_ios_predicate("label == ‘登入‘") driver.find_elements_by_ios_predicate("type=‘XCUIElementTypeOther‘ and name=‘連絡人,標籤, 第2個按鈕,共3個‘")
6、iOSUIAutomation
iOS9.3以下使用,現在已經廢棄,iOSPredicateString代替了iOSUIAutomation
移動端自動化==>Appium定位方式總結