码迷,mamicode.com
首页 > 移动开发 > 详细

appium 元素定位find_element_by_android_uiautomator方法使用

时间:2017-12-22 00:43:59      阅读:422      评论:0      收藏:0      [点我收藏+]

标签: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 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 手動添加‘‘‘ 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方法使用

标签:info   inf   通过   init   name   from   test   意思   bsp   

原文地址:http://www.cnblogs.com/syw20170419/p/8082896.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!