How to get all Children of Parent class?

#1

Hello,

I have an ‘android.widget.FrameLayout’ class which contains ‘android.widget.RelativeLayout’ class which contains ‘android.view.View’ class.

I want to query the Parent class for its children and then interact with the one I want (doesn’t sound so good :slight_smile: )
How can I get all children of the Parent class ?

Cheers,
Liran

0 Likes

#2

Hi Liran

The XPath will be in the form of

//android.widget.FrameLayout//android.widget.RelativeLayout//android.view.View

To break it down

1. // - All children and descendants of the root element 
2. android.widget.FrameLayout - class name is - android.widget.FrameLayout
3. / - Only first hand children (just one level)

for more info

https://www.w3schools.com/xml/xpath_syntax.asp

And if you want to iterate on the elements from the tool

 List<AndroidElement> webElementList = driver.findElements(By.xpath("//android.widget.FrameLayout//android.widget.RelativeLayout//android.view.View"));
        webElementList.forEach(webElement -> System.out.println(webElement.getText()));

0 Likes