【发布时间】:2021-08-21 12:55:10
【问题描述】:
我正在为 Android 应用编写自动化测试。
当我试图获取文章标题的内容描述时。我无法获取它。
仅供参考,我没有文字。
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
【问题讨论】:
-
我假设 getAttribute("content-desc") 和 getAttribute("contentDesc") 不起作用(它不应该但是......)。我希望有一种方法可以检索所有属性:)
-
@kiedysktos 你能告诉我它是怎么做的吗?
-
String contentDesc = property.getAttribute("content-desc");
-
@kiedysktos 它对我不起作用,并说找不到元素。
-
那我就不知道了……