How to findObject in UiAutomator using position on screen (bounds)

5.8k views Asked by At

I want to use device.findObject() to find an object in my screen, which requires a UiSelector. So far so good.

The problem is that I have several items only distinguishable by their position on the screen, e.g., in the messaging application all the Avatars have the same properties, except for their position in the screen.

How can I specify this?

I thought of:

  • checking the property after it found the object and do the search again without this one but I can't find any way of eliminating an object from a search neither.
  • using UiCollection to get all possibles elements and then check one by one which is the correct one. Problem: I can't use a foreach in UiCollection, to find an element I can only use a UiSelector, which has the same problem as before.

Do you have any sugestions/solutions?

Thanks.

1

There are 1 answers

1
Allen Hair On BEST ANSWER

It's not a great solution, but you could use UiDevice.findObjects(..) to return all of them. Then use getVisibleBounds() or getVisibleCenter() to check the coordinates.