【移动自动化】【三】控件定位

常用定位方法

  • id
  • Accessibility ID
  • xpath

http://appium.io/docs/en/commands/element/find-elements/

id

  1. 打开uiautomator view
  2. python中寻找id对应的 android的resource-id;iOS的name
  3. 用法可参考ch2/test_id.py
driver.find_element_by_id('com.shoumi.shoumi:id/tvSearchResult')

Accessibility ID

  1. Accessibility ID 对于的安卓中的content-desc
driver.find_element_by_accessibility_id()

xpath

  • 绝对定位:根据严格的父子关系定位
  • 相对定位:根据条件匹配定位
  • 注意xpath定位比较慢,因为需要递归解析每个元素的属性
  • 常用方法
  1. 查找
  • //*[@text='']
  • //*[@contains(@text, '')]
  1. 条件匹配
  • //*[contains(@resource-id, '') and contains(@text, '')]]
  • //*[contains(@resource-id, ‘login’) or contains(@text, ‘登录’)]]
  • 脚本中使用
  1. 可参考ch2/test_path.py,演示省略
driver.find_element_by_xpath()

github

https://github.com/wangxiao9/appium_demo.git

原文地址:https://www.cnblogs.com/totoro-cat/p/13453318.html