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定位

扫描二维码关注公众号,回复: 6205566 查看本文章

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定位

猜你喜欢

转载自www.cnblogs.com/JcHome/p/10851086.html