Get child elements not recursive

I want to get all child elements of an element, but ony from the next level, not their children’s children.
Basically I have the following structure:

RelativeLayout (can be found by id:rootID)
-RelativeLayout Y
--RelativeLayout N
--RelativeLayout N
-RelativeLayout Y
--RelativeLayout N
-RelativeLayout Y

I want to get a list of all elements tagged with Y (only the dircet children)

It can be done by calling:
–> this works and I get back the 3 elements with Y

But when trying to get the root Element by ID and then using a relative xPath, it doesn’t works:
–> the result is an empty list.

When trying the following:
–> I get back all RelativeLayouts, also the children’s children. Size: 6

Is there a way of doing this right?

Thank you for your answers! :slight_smile:

1 Like

I found a solution by myself:
@AndroidFindBy(xpath = "//*[@resource-id=\"\"]/*")

It works but I am not completely happy with that solution
Is there no way of chainning a findByID with an findByXpath?

1 Like