码迷,mamicode.com
首页 > 移动开发 > 详细

关于 appium get_attribute 方法的坑

时间:2019-03-01 12:09:49      阅读:353      评论:0      收藏:0      [点我收藏+]

标签:特殊   support   get   元素   运行   selected   业务   不能   uri   

 

(得要学着看源码)

问题:

self.driver.find_element_by_id("id").get_attribute("content-desc"), 会报NoSuchElement异常,经过验证是get_attribute的问题

问题原因探究:需要学会分析排插定位问题的根源,最关键还是要理解业务、底层代码、调用库实现流程的原理

 

appium server 在 android 原生应用上获取 attribute 的大致流程为:

  1. 从 client 收到获取 attribute 的请求
  2. 把请求转发给在手机上运行的 bootstrap
  3. bootstrap 调用相关方法进行实际操作
  4. bootstrap 返回结果给 appium server
  5. appium server 把结果返回给 client

通过排查各部分的代码发现,错误是在 bootstrap 产生的(排查过程涉及代码有点多,所以这里就不解释了),所以看看 bootstrap 相关源码:

技术图片

技术图片

 

其中`getStringAttribute``getBoolAttribute`源码如下:

技术图片

技术图片

 

总结:

1、获取 content-desc 的方法为 get_attribute("name") ,而且还不能保证返回的一定是 content-desc (content-desc 为空时会返回 text 属性值)
2、get_attribute 方法不是我们在 uiautomatorviewer 看到的所有属性都能获取的(此处的名称均为使用 get_attribute 时使用的属性名称):

可获取的:

字符串类型:

  • name(返回 content-desc 或 text)
  • text(返回 text)
  • className(返回 class,只有 API=>18 才能支持)
  • resourceId(返回 resource-id,只有 API=>18 才能支持)

布尔类型(如果无特殊说明, get_attribute 里面使用的属性名称和 uiautomatorviewer 里面的一致):

获取不到,但会显示在 uiautomatorviewer 中的属性:

    • index
    • package
    • password
    • bounds(可通过 get_position 来获取其中部分内容)

 

 

关于 appium get_attribute 方法的坑

标签:特殊   support   get   元素   运行   selected   业务   不能   uri   

原文地址:https://www.cnblogs.com/blogofzxf/p/10455394.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!