我正在seleium中进行自动化项目,我需要获取操作栏中包含的元素数量。 我正在使用appium和UI automator。 下面是元素的截图。 现在,我希望得到DriverLayout的子元素的列表(或计数)。
我正在使用
nonlocal
知道如何从String actionbarlayout = "android.support.v4.widget.DrawerLayout";
WebElement li = driver.findElementByClassName(actionbarlayout);
获取节点/元素列表?
非常感谢。
答案 0 :(得分:4)
为什么要查找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
}