標籤: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方法使用