【问题标题】:How to get content-desc attribute of an element in android using appium with ruby如何使用appium和ruby在android中获取元素的content-desc属性
【发布时间】: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。如果不起作用,请尝试使用其他定位器

标签: android ruby appium


【解决方案1】:

尝试使用getAttribute("contentDescription")

【讨论】:

    【解决方案2】:

    在 python 中(我猜与 Ruby 会类似)我这样做:

    Python 代码

    webElement = driver.find_element(By.XPATH, "//android.widget.TextView[@text='Automation']")
    content-desc = webElement.get_attribute("content-desc")
    print(content-desc)
    

    这个webElement.get_attribute(attr)适用于@text、@checked、@enabled、@selected、@name、@value……

    但是无论如何...您在找不到元素的地方发布了此消息:

    [AndroidBootstrap] [BOOTSTRAP LOG] [debug] 返回结果:{"status":7,"value":"This element does not have the 'content-desc' attribute"}

    所以也许你的 XPATH 不正确并且你选择了错误的元素...... 如果这对您不起作用,您必须发布 Appium Inspector 的图片才能为您提供帮助

    【讨论】:

      猜你喜欢
      • 2014-11-20
      • 1970-01-01
      • 2017-04-06
      • 2020-02-19
      • 1970-01-01
      • 2015-01-14
      • 2020-03-26
      • 2020-03-29
      • 1970-01-01
      相关资源
      最近更新 更多