2

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.

Inês
  • 882
  • 3
  • 13
  • 28
  • Were you able to click an element using bounds? I am currently unable to so. I am using `appium_lib` gem to automate and used the adb command `system('adb shell input tap 43,676 265,972')` to click the coordinates, but this doesnt seem to help. I guess, I am going wrong with the way I am writing the command, Do you have any soltion? @Ines – Emjey Mar 22 '17 at 19:56
  • 1
    I was able to do it with UiDevice.findObjects as suggested by Allen is the answer that's marked as correct. At least I think I was this was a long time ago... I've never worked with appium though. However, I'd say using adb shell can not be the best solution... – Inês Mar 24 '17 at 00:21
  • Yes! The bounds changing from device to device. It passes in my local emulator but fails on the CI. I then had to write a longer line of xpath and luckily I was able to locate the element. Thank you! – Emjey Mar 24 '17 at 04:09

1 Answers1

4

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.

Allen Hair
  • 1,021
  • 2
  • 10
  • 21