【问题标题】:Count the number of child elements in Appium UIAutomator统计 Appium UIAutomator 中子元素的数量
【发布时间】:2017-04-14 05:17:33
【问题描述】:
我在 seleium 中做一个自动化项目,我需要获取我的操作栏包含的元素数量。
我正在为此使用 appium 和 UI automator。
下面是元素的截图。
现在,我希望获取 DriverLayout 的子元素的列表(或计数)。
我正在使用
String actionbarlayout = "android.support.v4.widget.DrawerLayout";
WebElement li = driver.findElementByClassName(actionbarlayout);
知道如何从 li 获取节点/元素列表吗?
非常感谢。
【问题讨论】:
标签:
android
selenium
automation
appium
ui-automation
【解决方案1】:
为什么要查找actionbarLayout中所有项目的列表?我觉得找到所有相似元素的数量更有意义。例如,您可以找到 TextView 类型的所有元素的列表。代码是 -
List<WebElement> allTextViews = li.findElements(By.ClassName("android.widget.TextView"))
for(WebElement element : allTextViews) {
System.out.println(element.getAttribute("name")); //This returns the content-desc property
}