Best strategy to locate duplicate elements

Hello,

I need to test an app where the user can choose element from a library, and do a “drag and drop”.
That means that on the same screen I have the “Template elements” in the library, and the element that have been dropped (See uploaded image)

What is the best way to differentiate between these, when their attributes are identical (Same id, same text, etc…) ?

I was thinking of these solutions :

  1. By using the coordinates, I know that the library is on the right end of the screen, so I could use the X coordinates

  2. Maybe Appium scans the screen in a particular order (Left to right ? ) And then I know that the last element found is the one from the library

  3. Maybe there is a way to specify the parent of an element I’m looking for ?

Thanks,

Best way - ask dev to make same element ids

First of all, if they are on different sections of the screen I would guess they have different parents in the hierarchy so this maybe one option to go with.
Personally, I would adjust the mobile code and not the id specifically because the elements are of the same ‘type’. I would go to the part in the code(mobile’s code) where the location of the elements is changing and I would change the ‘selected’ attribute for example or passing some other indication with different attributes available to appium(check on appium inspector).
Then, let’s say you change the value of the ‘selected’ field to true when the element is “dropped” and changing it back to false when the element is in the “library”.
Then you can detect the change from your automation code and even locate the element using it.

Thanks a lot for the answers I will try these