How to get list of child elements of an element in Appium? How to get list of child elements of an element in Appium? selenium selenium

How to get list of child elements of an element in Appium?


You're almost there. What you have is giving you a list of all UIAWindows when what you want is a list of all the elements of the first UIAWindow. I'd suggest using Xpath with a wildcard.

This will get you every element that is a direct child of the first UIAWindow:

List<MobileElement> elements = driver.findElements(MobileBy.xpath("//UIAWindow[1]/*");

And this will get you every child and sub-child and sub-sub-child etc. of the first UIAWindow:

List<MobileElement> elements = driver.findElements(MobileBy.xpath("//UIAWindow[1]//*");

An extra tip: If you're automating for iOS, I assume that means you have access to OS X, where you can install the Appium dot app and use inspector. The inspector is a great tool to test out xpath queries before putting them into your code.


You can also find textfield and label by its class for iOS app in Appium. findElementsByClassName method will return all elements on current screen that matches that class.

List<MobileElement> textFields = driver.findElementsByClassName("UIATextField");MobileElement textField = textFields.get(0);List<MobileElement> labels = driver.findElementsByClassName("UIAStaticText");MobileElement label = labels.get(0);