TestProject Forum
Powered by leading experts in the test automation community

Selecting element that have no unique identifiers

hello @ran.tzur
Suppose i have four same elements A on one screen.
all four elements have same resource-ids,classname i.e no unique identifiers
can i select the element on the base of its instance without using tree(xpath)?
i want to select the element at first instance or second/third/fourth instance?
is it possible? if possible how can i do that?

Hello @ahmad
The best way to achieve it is by selecting the element you want within the locator strategy.
If you are using XPATH for example, you can use array notation.

For example:
(//div/span)[2]
Will select the second element.

HELLO @ran.tzur
in android the xpath for element using tree is like something like this
//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[2]/android.widget.LinearLayout[1]/android.widget.TableLayout[1]/android.widget.TableRow[1]/android.widget.LinearLayout[5]/android.widget.ImageView[1]​

locator is not able to find the element as the tree structure is continuously changing and there are no unique identifiers
without approaching the developer how can i handle it ?

You will need to find some parent element which has a static value, maybe text or another attribute, and from there traverse to the element you are searching for.

You can use the Element Explorer to check for the element that can help you.

image

1 Like