Appium无法获取“content-desc”属性数据

时间:2014-09-25 23:17:34

标签: java android appium

在下面的例子中,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:元素不能   位于页面上使用给定的搜索参数。 (警告:   服务器没有提供任何堆栈跟踪信息)

4 个答案:

答案 0 :(得分:16)

使用&#34;名称&#34;

property.getAttribute("name");

答案 1 :(得分:1)

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

布尔属性是:

  • 启用
  • 辨认的
  • 检查
  • 可点击
  • 可聚焦
  • 聚焦
  • longClickable
  • 滚动
  • 选择
  • 显示

字符串属性为:

  • contentDescription
  • 文本
  • 的className
  • RESOURCEID

我使用python绑定测试了这个。

信用转到TikhomirovSergey中的github comment

答案 2 :(得分:0)

试试这个:

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

答案 3 :(得分:-1)

text可以用作

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

OR content-desc可以用作

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

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

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