若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

 看了一会,愣是没有明白给出的示例是什么意思,实际脚本中怎么运用,我知道是自己太笨了,所以果断还是找能看懂的示例进行学习吧,因此哈哈还真找到了,将此运用方式写成简单的示例来记录,说明:这里已text为例,其余的uiautomator中的方法使用形式与此一致,因此会一个足以按照此方式来实现其他需求。

示例如下:

# coding=UTF-8
'''
Created on 2017.12.21
@author: Lucky
'''from appium import webdriver

class 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 手動添加'''find_element_by_android_uiautomator('text(\"列表\")').click() #点击 字符串“列表”

  #第二种 通过参数的给定来操作
  def Enter_Customer_List2(self,name):
find_element_by_android_uiautomator('text(\"'+name+'\")').click()
if __name__ == "__main__":
  c = Customer()
  c.Enter_Customer_List()
  c.Enter_Customer_List('列表')


 1.作者:Syw

2.本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

3.如果文中有什么错误,欢迎指出。以免更多的人被误导。