java Appium无法获取“content-desc”属性数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26049651/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Appium unable to get "content-desc" attribute data
提问by gorbysbm
In the below case, Appium is correctly able to locate elements by class, but when we want to manipulate the data based on each element's content-descwe see an error. Why can't we get attribute for content-desc? Any advice appreciated.
在下面的例子中,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);
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)
错误:找到 arrayOfProperties2 总计:32
org.openqa.selenium.NoSuchElementException:无法使用给定的搜索参数在页面上定位元素。(警告:服务器没有提供任何堆栈跟踪信息)
回答by TinyTimZamboni
Use "name"
使用名称”
property.getAttribute("name");
property.getAttribute("name");
回答by ibizaman
The list of accepted attribute names can be found in boolean attrbutesand string attributes.
The boolean attributes are:
布尔属性是:
- enabled
- checkable
- checked
- clickable
- focusable
- focused
- longClickable
- scrollable
- selected
- displayed
- 启用
- 可检查的
- 检查
- 可点击
- 可聚焦
- 专注
- 长点击
- 可滚动
- 被选中
- 显示
The string attibutes are:
字符串属性是:
- contentDescription
- text
- className
- resourceId
- 内容描述
- 文本
- 班级名称
- 资源编号
I tested this using the python bindings.
我使用 python 绑定对此进行了测试。
Credit goes to TikhomirovSergeyin a github comment.
回答by Alle Srinivas
text
can be used as
text
可以用作
driver.findElement(By.xpath("//*[@text='Remove Contact']"))
OR content-desc
can be used as
ORcontent-desc
可以用作
driver.findElement(By.name("Remove Contact"))
driver.findElement(By.xpath("//*[@content-desc='Remove Contact']"))
driver.findElement(By.name("Remove Contact"))
回答by CLuhring
try this:
试试这个:
driver.findElement(By.AccessibilityID(""));
driver.findElement(By.AccessibilityID(""));