zoukankan      html  css  js  c++  java
  • Appium+Python 自动化appium常用元素定位方法

    https://www.cnblogs.com/rabbit-testing/p/8042733.html 大牛

    https://blog.csdn.net/kaka1121/article/details/53301517 大牛

    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() 



    知识无穷尽也。

  • 相关阅读:
    类型化dataset分页
    cp自动创建层级结构的例子
    You have tried to change the API from what has been previously approved.
    Mysql学习笔记
    cygwin设置NDK环境变量ANDROID_NDK_ROOT
    PowerDesigner学习笔记
    Spring Cloud Commons教程(三)忽略网络接口
    Spring Cloud Commons教程(二)Spring RestTemplate作为负载平衡器客户端
    Spring Cloud Commons教程(一)普通抽象
    Spring Cloud教程(十二)加密和解密
  • 原文地址:https://www.cnblogs.com/mapu/p/8613340.html
Copyright © 2011-2022 走看看