iOSNsPredicate Appium 定位元素

來源:互聯網
上載者:User

標籤:模糊   class   sel   end   模糊比對   ntb   官方   running   參考   

Appium使用WebDriverAgent之後,新增了一種定位方法iOSNsPredicate,總結了一下使用方法:

 

MobileElement photo = driver.findElementByIosNsPredicate("name = ‘head new‘"); // 等於

MobileElement photo = driver.findElementByIosNsPredicate("name LIKE ‘*new‘");  // 模糊比對

MobileElement photo = driver.findElementByIosNsPredicate("name MATCHES ‘^$‘"); // Regex匹配

List<IOSElement> items1 = driver.findElementsByIosNsPredicate("name CONTAINS ‘我的‘"); // 包含

List<IOSElement> items2 = driver.findElementsByIosNsPredicate("name BEGINSWITH ‘我的‘"); // 以"我的"開始

List<IOSElement> items3 = driver.findElementsByIosNsPredicate("name BEGINSWITH ‘我的‘ && name ENDSWITH ‘訊息‘"); // 以"我的"開始並且以"訊息"結尾

 

其中屬性名稱參照inspector的屬性欄位,關鍵字LIKE,MATCHES,CONTAINS,BEGINSWITH,ENDSWITH必須是大寫,匹配的字元需要用單引號

官方參考地址:

https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/ios_predicate.md

 

最後給個建議:

1 選擇定位方式的判斷:

  如果顯示在介面的文本唯一或是第一個出現:使用accessibility

  如果class唯一或是第一個出現:className

  ID或class不方便定位,控制項屬性有明確的匹配規則:accessibility

  如果有工具可以直接給出準確的xpath:xpath

  實在不行就用座標吧

2 如果控制項的屬性visible是false的話,請使用控制項座標並擷取中心點用tap點擊,直接點擊控制項會失敗

iOSNsPredicate Appium 定位元素

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.