Appium-python自动化(五) 定位元素(二)

  • appium在android的底层用的引擎是uiautomator2自动化化测试框架去驱动自动化执行的,在定位元素的时候,可以借助uiautomator2的语法实现元素的定位。
  • uiautomator2的语法定位比xpath的速度快,但是书写复杂,IDE没有提示容易写错

用uiautomator2定位的话书写方式是:newUiSelector().属性名("属性值")

根据resourceId定位: driver.find_element(MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceid("id值")')
根据className定位: driver.find_element(MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().className("class值")')
根据content-desc定位: driver.find_element(MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().description("content-desc值")')
根据text属性定位:全匹配 driver.find_element(MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("text属性值")')
根据text属性定位:模糊匹配 driver.find_element(MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().textContains("text属性值")')
根据text属性定位:以文本开头匹配 driver.find_element(MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().textStartsWith("text属性值的开头一部分")')
根据text属性定位:以正则匹配 driver.find_element(MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().textMatches("正则表达式")')
组合定位:类名+文本 'new UiSelector().className("class的值").text("text属性的值"))'
组合定位:id+文本 'new UiSelector().resourceId("resource-id属性的值").text("text属性的值")'
其他属性也可以任意组合进行定位  
   
   
   
   
   
   
   

相关文章

前言:appium可以说是app最火的一个自动化框架,它的主要优势...
(原文:https://www.cnblogs.com/fancy0158/p/10047906.htm...
一Appium介绍1.1含义开源,跨平台,多语言支持的移动应用自动...
前言:Appium是一个自动化测试开源工具,支持iOS平台和Andro...
转:https://blog.csdn.net/Tigerdong1/article/details/801...
(原文:https://www.cnblogs.com/fancy0158/p/10056418.htm...