【appium】根據UIAutomator定位元素

來源:互聯網
上載者:User

標籤:

text屬性的方法
driver.find_element_by_android_uiautomator(‘new UiSelector().text("Custom View")‘).click()         #textdriver.find_element_by_android_uiautomator(‘new UiSelector().textContains("View")‘).click()        #textContainsdriver.find_element_by_android_uiautomator(‘new UiSelector().textStartsWith("Custom")‘).click()    #textStartsWithdriver.find_element_by_android_uiautomator(‘new UiSelector().textMatches("^Custom.*")‘).click()    #textMatches

 

class屬性的方法

 

driver.find_element_by_android_uiautomator(‘new UiSelector().className("android.widget.TextView").text("Custom View")‘).click()     #classNamedriver.find_element_by_android_uiautomator(‘new UiSelector().classNameMatches(".*TextView$").text("Custom View")‘).click()          #classNameMatches

 

 偽xpath方法定位

driver.find_element_by_android_uiautomator(‘new UiSelector().text("Custom View").fromParent(new UiSelector().text("Accessibility Service"))‘).click()            #通過同級元素定位同級元素driver.find_element_by_android_uiautomator(‘new UiSelector().className("android.widget.ListView").childSelector(new UiSelector().text("Custom View"))‘).click()  #通過父級元素定位子集元素

 resourceId屬性的方法


driver.find_element_by_android_uiautomator(‘new UiSelector().resourceId("android:id/text1")‘)    #resourceIddriver.find_element_by_android_uiautomator(‘new UiSelector().resourceIdMatches(".*id/text1$")‘)  #resourceIdMatches

description屬性的方法
driver.find_element_by_android_uiautomator(‘new UiSelector().description("Custom View")‘).click()      #descriptiondriver.find_element_by_android_uiautomator(‘new UiSelector().descriptionStartsWith("Custom")‘).click() #descriptionStartsWithdriver.find_element_by_android_uiautomator(‘new UiSelector().descriptionMatches("^Custom.*")‘).click() #descriptionMatches

 元素的其他屬性

除了以上比較常用的方法外,UIAutomator還支援其他一些方法,比如根據控制項屬性是否可點擊可聚焦可長按等來縮小要定位的控制項的範圍,具體使用方法不一一列舉(checked,clickable,focesed.......)

 

driver.find_element_by_android_uiautomator(‘new UiSelector().clickable(true).text("Custom View")‘).click() 

 

 

 

【appium】根據UIAutomator定位元素

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.