【发布时间】:2018-06-04 00:55:53
【问题描述】:
我正在尝试使用获取元素的 content-desc 属性
@driver.find_element(:xpath, "//android.widget.TextView[@text='Automation']").attribute("content-desc")
但出现此错误
[debug] [MJSONWP] 使用 args 调用 AppiumDriver.getAttribute(): ["xpath","19","f0ea41e6-dfee-4b9b-b756-0b204863d0d4"]
[debug][AndroidBootstrap] 向安卓发送命令: {"cmd":"action","action":"element:getAttribute","params":{"attribute":"content-desc","elementId":"19"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] 从客户端获取数据: {"cmd":"action","action":"element:getAttribute","params":{"attribute":"content-desc","elementId":"19"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] 得到了 ACTION 类型的命令
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] 得到命令动作: 获取属性 [AndroidBootstrap] [BOOTSTRAP LOG] [debug] 返回 结果:{"status":7,"value":"这个元素没有 'content-desc' 属性"}
我已经检查了 appium UI 是否存在 content-desc 属性,我的代码有什么问题吗?有没有替代品?
【问题讨论】:
-
我相信您的代码是正确的,可能的错误可能是不正确的 xpath 或属性名称,因此我建议使用
contentDescription而不是 content-desc。如果不起作用,请尝试使用其他定位器