Appium 定位元素

Appium 元素定位

通过id定位

driver.find_element_by_id("com.tencent.mm:id/cw").click()

 

通过name定位:

driver.find_element_by_name("转转二手交…").click()

 

通过单独的class定位(比较少用,在app中不太实际,因为同一个页面存在class的标签太多,往往无法准确定位到想要定位的元素)

driver.find_element_by_class_name("android.widget.TextView").click()

 

通过xpath定位

driver.find_element_by_xpath("//android.support.v7.widget.RecyclerView[@resource-id='com.tencent.mm:id/pj']/android.widget.RelativeLayout[@class='android.widget.RelativeLayout']").click()

xpath 定位比较灵活,且可以通过多属性组合,更精准定位到元素的位置。如下:

driver.find_element_by_xpath("//android.widget.FrameLayout[@index='0' and @resource-id='com.tencent.mm:id/xr' and @class='android.widget.FrameLayout' ]").click()

 

通过坐标定位(不建议使用这种方式,因为手机分辨率不一致,导致点击无效)

driver.tap([(96,346)])

  

 

 

 

通过xpath定位

相关文章

前言: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...