Object index changes according with device

Getting different xpath for same element on different device.
OS of both devices: Android 7.0
Appium version: 1.10. 0
Need to find element using xpath since have to store the text in list and compare it further. As there is no unique id or text to identify the element, have to use only index of the element.

Cant you use resource id or Classname or name ?

Resource id and name not available. Classname of all classes are same.

I suggest you to ask your developer to add resource id or use class name because xpath is not something you can rely on while doing automation.

Ok. But why index of class changes according to the devices we use.

As per my knowledge you can see object indexes based on the number of element visible on the screen.

If screen size is large and you have 10 objects with same ids then it will create index from 0 to 9 and if another device which is small in size will show only 7 objects then you’ll be getting indexes from 0 to 6.

I hope this is the case you are facing.

1 Like