The same elements in application have different Ids

I’m trying to recognize if two objects returned by Appium driver are equal.

AppiumWebElement element1 = driver.FindElementById("id/Car");
AppiumWebElement element2 = driver.FindElementById("id/Car");
string id1 = element1.Id;
string id2 = element2.Id;

element1 and element2 are different objects with different references. The ID of element1 is “1” and the ID of element2 is “2”. Why are these IDs different? Secondly, how would you determine if AppiumWebElement is pointing to the same Android element?

First of all, I didn’t know this until now :smile: so nice find!

I also tried it with iOS and MobileElement but results are still the same. So I think it leaves us with this: IDs generated by Appium does not work as pointers (as I thought before)

findElement generates a MobileElement or an AppiumWebElement based on the element you pointed at it, and it seems it just gets all relevant data about the element (attributes, coordinates etc.) and creates an object based on the properties.

Other than the properties, the IDs set by Appium are generated randomly; you can even set them as you like.

Regarding your problem with comparing two elements, my advice would be comparing coordinates and/or sizes, considering the screen stays the same between fetching the elements.

Good luck