【问题标题】:Appium unable to get "content-desc" attribute dataAppium 无法获取“content-desc”属性数据
【发布时间】:2014-11-20 21:07:08
【问题描述】:

在下面的例子中,Appium 能够正确地按类定位元素,但是当我们想要根据每个元素的 content-desc 操作数据时,我们会看到错误。为什么我们不能获取 content-desc 的属性? 任何建议表示赞赏。

    List<WebElement> arrayOfProperties2 = driver.findElementsByClassName("android.view.View");
    List<WebElement> propertyMarkerEle = new ArrayList<>();

    System.out.println("Found arrayOfProperties2 total: "+ arrayOfProperties2.size());

    for (WebElement property : arrayOfProperties2){
        String contentDesc = property.getAttribute("content-desc");
        if (contentDesc.contains("property"))
            propertyMarkerEle.add(property);

错误:找到 arrayOfProperties2 总数:32
org.openqa.selenium.NoSuchElementException:一个元素不能是 使用给定的搜索参数位于页面上。 (警告: 服务器没有提供任何堆栈跟踪信息)

【问题讨论】:

标签: java android appium


【解决方案1】:

使用“名称”

property.getAttribute("name");

【讨论】:

  • 嗨,driver.findElementByXPath("android.widget.TextView[]").getAttribute("name");没有从应用程序获取属性文本..你能告诉我我在代码中哪里做错了..类,包和内容描述没有打印,但剩余的节点详细信息打印成功..我不知道出了什么问题..感谢提前
  • 那可能没有内容描述??
  • 发布来自 Google automator viewer 的屏幕截图,显示所有属性
  • 我试过这样:driver.findElementByXPath("android.widget.TextView[]").getAttribute("content-desc");但无法获取内容描述详细信息,甚至在应用元素上有内容描述。由于政策限制,我无法发布应用截图。剩余节点详细信息打印成功。
  • 不确定。查看xml源码的时候,里面的内容描述是否可见?
【解决方案2】:

text可以用作

driver.findElement(By.xpath("//*[@text='Remove Contact']"))

或者content-desc可以用作

driver.findElement(By.name("Remove Contact"))

driver.findElement(By.xpath("//*[@content-desc='Remove Contact']"))

driver.findElement(By.name("Remove Contact"))

【讨论】:

  • 在 python 中,content-desc 似乎没有映射到 find_element_by_name。唉!
【解决方案3】:

试试这个:

driver.findElement(By.AccessibilityID(""));

【讨论】:

    【解决方案4】:

    可以在boolean attrbutesstring attributes 中找到接受的属性名称列表。

    布尔属性是:

    • 启用
    • 可检查
    • 已检查
    • 可点击
    • 可聚焦
    • 专注
    • longClickable
    • 可滚动
    • 已选择
    • 显示

    字符串属性为:

    • 内容描述
    • 文字
    • 类名
    • resourceId

    我使用 python 绑定对此进行了测试。

    信用在github comment 中转到TikhomirovSergey

    【讨论】:

      猜你喜欢
      • 2017-04-06
      • 2018-06-04
      • 2020-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-23
      • 1970-01-01
      • 2019-08-12
      相关资源
      最近更新 更多