标签:特殊 support get 元素 运行 selected 业务 不能 uri
(得要学着看源码)
问题:
self.driver.find_element_by_id("id").get_attribute("content-desc"), 会报NoSuchElement异常,经过验证是get_attribute的问题
问题原因探究:需要学会分析排插定位问题的根源,最关键还是要理解业务、底层代码、调用库实现流程的原理
appium server 在 android 原生应用上获取 attribute 的大致流程为:
通过排查各部分的代码发现,错误是在 bootstrap 产生的(排查过程涉及代码有点多,所以这里就不解释了),所以看看 bootstrap 相关源码:
其中`getStringAttribute`和`getBoolAttribute`源码如下:
总结:
1、获取 content-desc 的方法为 get_attribute("name")
,而且还不能保证返回的一定是 content-desc (content-desc 为空时会返回 text 属性值)
2、get_attribute
方法不是我们在 uiautomatorviewer
看到的所有属性都能获取的(此处的名称均为使用 get_attribute 时使用的属性名称):
可获取的:
字符串类型:
布尔类型(如果无特殊说明, get_attribute 里面使用的属性名称和 uiautomatorviewer 里面的一致):
exists()
方法,详情请看 http://developer.android.com/reference/android/support/test/uiautomator/UiObject.html#exists())获取不到,但会显示在 uiautomatorviewer 中的属性:
标签:特殊 support get 元素 运行 selected 业务 不能 uri
原文地址:https://www.cnblogs.com/blogofzxf/p/10455394.html