zoukankan      html  css  js  c++  java
  • 八:Appium元素UIAutomator定位方式

    UIAutomator定位简介

    UIAutomator元素定位是 Android 系统原生支持的定位方式,虽然与 xpath 类似,但比它更加好用,且支持元素全部属性定位.定位原理是通过android 自带的android uiautomator的类库去查找元素。 Appium元素定位方法其实也是基于Uiautomator来进行封装的。
    使用方法 find_element_by_android_uiautomator() 可以运用UiAutomator元素定位。

    定位方法

    • id定位
    • text定位
    • class name定位

    id定位

    id定位是根据元素的resource-id属性来进行定位,使用 UiSelector().resourceId()方法即可。


    by_Uiautomator.py

    from find_element.capability import driver
    
    driver.find_element_by_android_uiautomator
        ('new UiSelector().resourceId("com.tal.kaoyan:id/login_email_edittext")').send_keys('zxw1234')
    
    driver.find_element_by_android_uiautomator
        ('new UiSelector().resourceId("com.tal.kaoyan:id/login_password_edittext")').send_keys('zxw123456')
    
    driver.find_element_by_android_uiautomator
        ('new UiSelector().resourceId("com.tal.kaoyan:id/login_login_btn")').click()

    text定位
    text定位就是根据元素的text属性值来进行定位,new UiSelector()

    driver.find_element_by_android_uiautomator
        ('new UiSelector().text("请输入用户名")').send_keys('zxw1234')

    class name定位
    与Appium class定位方式一样,也是根据元素的class属性来进行定位。

    driver.find_element_by_android_uiautomator
        ('new UiSelector().className("android.widget.EditText")').send_keys('zxw1234')
    from find_element.capability import driver
    # 基于Uiautomator 属性定位 id
    driver.find_element_by_android_uiautomator
        ('new UiSelector().resourceId("com.tal.kaoyan:id/login_email_edittext")').send_keys("榆12")
    driver.find_element_by_android_uiautomator
        ('new UiSelector().resourceId("com.tal.kaoyan:id/login_password_edittext")').send_keys("huzhenyu20017")
    driver.find_element_by_android_uiautomator
        ('new UiSelector().resourceId("com.tal.kaoyan:id/login_login_btn")').click()
    
    
    '''
    #基于Uiautomator 属性定位 text
    driver.find_element_by_android_uiautomator
        ('new UiSelector().text("请输入用户名")').send_keys("榆12")
    #基于Uiautomator 属性定位 class name
    driver.find_element_by_android_uiautomator
        ('new UiSelector().className("android.widget.EditText")').send_keys('zxw1234')
        5类都可以等等
    '''
  • 相关阅读:
    VIM于换行EOL的思考
    wp7给图片和按钮添加背景图片
    wp7打开加速度传感器
    java值传递、引用传递
    keychron k1长时间不使用蓝牙,蓝牙连接不上解决方案
    IE浏览器切换64位和32位
    文件和注册表的重定向解决方法
    Windows C++遍历所有进程的命令行
    c++ fstream open 失败原因
    解析wrk压测工具
  • 原文地址:https://www.cnblogs.com/zhenyu1/p/11943074.html
Copyright © 2011-2022 走看看