2014-09-25 321 views
5

在下面的例子中,Appium能够按类定位元素,但是当我们想要基于每个元素的内容处理数据时,我们看到一个错误。为什么我们不能获得content-desc的属性? 任何意见赞赏。Appium无法获得“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); 

Error: Found arrayOfProperties2 total: 32
org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)

+0

这可以帮助我猜测https://github.com/appium/appium/issues/5142。我相信代码更改被推入。 – nullpointer 2016-02-03 12:30:28

回答

15

使用 “名”

property.getAttribute("name");

+0

嗨,driver.findElementByXPath(“android.widget.TextView []”)。getAttribute(“name”);是不是从应用程序获取属性文本..你能告诉我我在代码中做错了什么?类,包和内容desc不打印,但剩余的节点详细信息打印成功..我不知道什么是错误的..感谢您提前 – 2014-09-28 17:01:39

+0

它可能没有内容描述呢? – TinyTimZamboni 2014-09-28 23:15:34

+0

No Tiny ..它具有特定元素的内容描述。 – 2014-09-29 04:00:46

-2

文本或 内容递减 可以作为

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

可以由用户在

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


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

可以作为

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

在python中,content-desc不会映射到find_element_by_name。唉! – kiminoa 2015-10-15 19:12:38

0

试试这个:

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

1

接受属性名的列表可以在boolean attrbutesstring attributes被发现。

布尔属性是:

  • 启用
  • 辨认的
  • 检查
  • 点击
  • 可聚焦
  • 集中
  • longClickable
  • scrolla竹叶提取
  • 选择
  • 显示

字符串attibutes是:

  • contentDescription
  • 文本
  • 的className
  • RESOURCEID

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

积分TikhomirovSergeygithub comment