统计Appium UIAutomator中的子元素个数

Count the number of child elements in Appium UIAutomator

我正在 seleium 中做一个自动化项目,我需要获取我的操作栏包含的元素数量。 我正在为此使用 appium 和 UI automator。 下面是元素的屏幕截图。 现在,我希望获得 DriverLayout 的子元素的列表(或计数)。

我正在使用

String actionbarlayout = "android.support.v4.widget.DrawerLayout";
WebElement li = driver.findElementByClassName(actionbarlayout);

知道如何从 li 获取 nodes/elements 列表吗? 非常感谢。

为什么要查找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
}