appium 元素定位find_element_by_android_uiautomator方法使用

來源:互聯網
上載者:User

標籤:info   inf   通過   init   name   from   test   意思   bsp   

若appium中給定的方法無法滿足你的需求,剛好uiautomator中的方法可以滿足你的需求時,你可使用find_element_by_android_uiautomator來調用uiautomator中的方法來實現。

appium底層檔案webdriver中給出的說明如下:

def find_element_by_android_uiautomator(self, uia_string):        """Finds element by uiautomator in Android.        :Args:         - uia_string - The element name in the Android UIAutomator library        :Usage:            driver.find_element_by_android_uiautomator(‘.elements()[1].cells()[2]‘)        """        return self.find_element(by=By.ANDROID_UIAUTOMATOR, value=uia_string)

 看了一會,愣是沒有明白給出的樣本是什麼意思,實際指令碼中怎麼運用,我知道是自己太笨了,所以果斷還是找能看懂的樣本進行學習吧,因此哈哈還真找到了,將此運用方式寫成簡單的樣本來記錄,說明:這裡已text為例,其餘的uiautomator中的方法使用形式與此一致,因此會一個足以按照此方式來實現其他需求。

樣本如下:

# coding=UTF-8‘‘‘Created on 2017.12.21@author: Lucky‘‘‘from appium import webdriverclass Customer:    def __init__(self):        logging.info("Test_appium.....setUp")          desired_cups = {}        desired_cups[‘platformName‘] = ‘Android‘        desired_cups[‘platformVersion‘] = ‘7.0‘        desired_cups[‘deviceName‘] = ‘aa‘          desired_cups[‘appPackage‘]= ‘com.ibroker.iBerHK‘          desired_cups[‘appActivity‘] = ‘.SplashActivity‘          self.device = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub‘,desired_cups)         self.device.implicitly_wait(20)    #全域預設等待最大時間            #第一種 直接點擊字串
  def Enter_Customer_List(self): ‘‘‘select:通訊錄導入 and 手動添加‘‘‘ self.device.find_element_by_android_uiautomator(‘text(\"列表\")‘).click() #點擊 字串“列表”

  #第二種 通過參數的給定來操作
  def Enter_Customer_List2(self,name):
 ‘‘‘select:通訊錄導入 and 手動添加‘‘‘ self.device.find_element_by_android_uiautomator(‘text(\"‘+name+‘\")‘).click() 

if __name__ == "__main__":
  c = Customer()
  c.Enter_Customer_List()
  c.Enter_Customer_List(‘列表‘)

 

appium 元素定位find_element_by_android_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.