前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >UIAutomator定位简介

UIAutomator定位简介

作者头像
清风穆云
发布2021-08-09 10:50:40
6780
发布2021-08-09 10:50:40
举报
文章被收录于专栏:QA一隅

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

代码语言:javascript
复制
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()

代码语言:javascript
复制

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

class name定位

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

代码语言:javascript
复制
driver.find_element_by_android_uiautomator\
    ('new UiSelector().className("android.widget.EditText")').send_keys('zxw1234')
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-07-14,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 QA一隅 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 定位方法
    • id定位
      • text定位
        • class name定位
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档