androidandroid-testingboundsuideviceandroid-uiautomator

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


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:

Do you have any sugestions/solutions?

Thanks.


Solution

  • 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.