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



    知识无穷尽也。

  • 相关阅读:
    「SDOI2014」向量集 解题报告
    HNOI 2014 世界树
    LOJ #2205. 「HNOI2014」画框 解题报告
    KM模板
    洛谷 [HNOI2014]道路堵塞 解题报告
    [AHOI2014/JSOI2014] 解题报告
    AndroidStudio中添加依赖的三种方式以及如何引入so文件和arr文件
    android 四大组件详解
    Android—— ListView 的简单用法及定制ListView界面
    Android Studio 使用VCS版本控制
  • 原文地址:https://www.cnblogs.com/mapu/p/8613340.html
Copyright © 2011-2022 走看看