learntogrow-growtolearn
learntogrow-growtolearn

Reputation: 1280

Count the number of child elements in Appium UIAutomator

I am doing an automation project in seleium and I need to get the number of elements that my action bar contains. I am getting using appium and UI automator for this. Below is the screenshot of the element. enter image description here Now, I wish to get the list(or count) of the children elements of the the DriverLayout.

I am using

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

Any idea how can I get the nodes/elements list from li ? Thanks a lot.

Upvotes: 1

Views: 2329

Answers (1)

Anish Pillai
Anish Pillai

Reputation: 1023

Why do you want to find the list of all the items in the actionbarLayout? I feel that finding the count of all similar elements makes more sense. For example, you can find the list of all the elements of type TextView. The code for that would be -

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
}

Upvotes: 4

Related Questions