如何使用 appium 在 Android 应用中获取 content-desc [英] How to get content-desc in Android app using appium
问题描述
我正在为 Android 应用编写自动化测试.
I am writing automation test for Android app.
当我尝试获取文章标题的 content-desc 时.我无法获取它.
When I am trying to get content-desc for article title. I am not able to fetch it.
仅供参考,我没有文字.
FYI I don't have text.
List<WebElement> arrayOfProperties2 = driver.findElementsByClassName("android.view.View");
for (WebElement property : arrayOfProperties2){
System.out.println("property" + property.getClass());
String contentDesc = property.getAttribute("name");
String contentDesc1 = property.getAttribute("className");
String contentDesc2 = property.getAttribute("resourceId");
System.out.println("contentDesc" + contentDesc);
System.out.println("contentDesc1" + contentDesc1);
System.out.println("contentDesc2" + contentDesc2);
}
结果:-
contentDesc
contentDesc1android.view.View
contentDesc2
推荐答案
关注 appium 文档 http://appium.io/docs/en/commands/element/find-elements/
Following appium docs http://appium.io/docs/en/commands/element/find-elements/
使用 findElementByAccessibilityId
或 findElementsByAccessibilityId
你得到:
Using findElementByAccessibilityId
or findElementsByAccessibilityId
you get:
辅助功能 ID
读取 UI 元素的唯一标识符.对于 XCUITest,它是元素的 accessibility-id
属性.对于 Android,它是元素的 content-desc
属性.
Read a unique identifier for a UI element. For XCUITest it is the element's accessibility-id
attribute. For Android it is the element's content-desc
attribute.
这篇关于如何使用 appium 在 Android 应用中获取 content-desc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!