Android元素定位一般使用Android平台自带的UI Automator Viewer,位于Android-sdk的tools目录下,找到uiautomatorviewer.bat,双击打开即可使用,最主要的三种定位方法如下:

1.通过id定位元素,Android里面定位的id一般为resrouce-id:

Click Element   id=com.ewei.helpdesk:id/tv_common_finish

2.通过name定位元素,text属性则是name:

Click Element   name=保存

3.通过ClassName定位元素,classname指的是class属性:

Wait Until Element Is Visible   class=android.widget.TextView

但某些特殊情况下,text为空,resrouce-id和class属性相同,如下图,则只能使用xpath定位


Android中的元素定位_第1张图片 image.png

在众多的xpath语法中,xpath里面有一个轴,简单点理解为一个函数。preceding-sibling:: 可以找到节点前面也就是哥哥节点,following-sibling::可以找到节点后面也就是弟弟节点,那么此处定位客户后的元素则可以如下处理:

Click Element   xpath=//android.widget.TextView[@text='*客户']/following-sibling::android.widget.TextView

另外,xpath还有contains函数,类似xpath=//android.widget.TextView[contains(@text,'*客户')],也是可以达到定位效果。

更多相关文章

  1. Fresco属性
  2. Android SystemProperties 系统属性分析
  3. Android ListView几个比较有用的属性
  4. xml-----属性收集
  5. ListView的一些属性
  6. Android 属性动画Property Animation(下)
  7. 关于android的animation的xml定义中的android:interpolator属性
  8. Android UI元素使用初步

随机推荐

  1. Android(安卓)抓包分析
  2. 开源项目之Android-GL(OpenGL 编程)
  3. Android(安卓)与 SQLite
  4. android学习笔记21:日期时间控件
  5. Android(安卓)自定义左滑删除列表
  6. AChartEngine api说明
  7. retrofit rxjava android 封装 使用
  8. Android实现新手引导半透明蒙层效果
  9. Android常用三方框架
  10. APK打包过程中出现Error:"app_name" is n