Appium+Python 自動化-appium常用元素定位方法


ID定位

# resourceId屬性的方法
driver.find_element_by_id('com.lizi.app:id/setting_imageView').click()
#以accessibility_id進行定位,對Android而言,就是content-description屬性
driver.find_element_by_accessibility_id('push_button').click()

ClassName 定位

# 定位唯一元素  
self.driver.find_element_by_class_name("android.widget.EditText")
# 找到所有android.widget.EditText並定位第一個
self.driver.find_elements_by_class_name("android.widget.EditText")[0]

Name 定位

#根據name進行定位,對於android來說,就是text屬性
driver.find_element_by_name(u"登 錄").click() 

 Xpath 定位

driver.find_elements_by_xpath('//android.widget.TextView[@resource-id="com.mzdk.app:id/item_good_title"]')[1].click()

Uiautomator 定位

  • text屬性的方法

driver.find_element_by_android_uiautomator('new UiSelector().text("Custom View")').click()         #text
driver.find_element_by_android_uiautomator('new UiSelector().textContains("View")').click()        #textContains
driver.find_element_by_android_uiautomator('new UiSelector().textStartsWith("Custom")').click()    #textStartsWith
driver.find_element_by_android_uiautomator('new UiSelector().textMatches("^Custom.*")').click()    #textMatches
  • class屬性的方法
#className
driver.find_element_by_android_uiautomator('new UiSelector().className("android.widget.TextView").text("Custom View")').click()
#classNameMatches driver.find_element_by_android_uiautomator('new UiSelector().classNameMatches(".*TextView$").text("Custom View")').click()
  •  resourceId屬性的方法
#resourceId
driver.find_element_by_android_uiautomator('new UiSelector().resourceId("android:id/text1")')
#resourceIdMatches
driver.find_element_by_android_uiautomator('new UiSelector().resourceIdMatches(".*id/text1$")')
  •  元素的其他屬性
driver.find_element_by_android_uiautomator('new UiSelector().clickable(true).text("Custom View")').click() 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM