Reputation: 466
Very new to Android Testing.
I came across this Xpath
xpath: (//android.widget.ImageView[1])[3]
I know that in ImageView1 "1" is the index of the element.
What is [3] here???
Update:
I am running a test (mobile App). The above XPath is to tap on the Bell icon.
It did tap on the bell icon perfectly.
But today when I run my test it doesn't tap on the Bell icon instead it taps on the user Profile Picture.
Using appium I found the xpath of the Bell icon as below:
xpath: /hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[1]/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[2]/android.view.ViewGroup[1]/android.view.ViewGroup[2]/android.view.ViewGroup/android.widget.ImageView
Now when I use this new xpath the Bell icon is clicked.
Are both the Xpaths same??
Why is this new xpath so long? is there a way to shorten this??
Any kind of help is really Appreciated!!!
Upvotes: 0
Views: 1493
Reputation: 73
You are getting the absolute xpath using the appium(which you have stated above) and the one you are using like //android.widget.ImageView[1])[3] is the relative xpath of the icon.
Absolute xpath : It is the path from the root element to the particular element. Relative xpath : It is the reference path of the element or particular path to the element.
Upvotes: 0
Reputation: 31
Try to access bell button using class name.
(//*[@class="Class name"])[2]
(//*[@class="android.widget.ImageView"])[2]
Upvotes: 0
Reputation: 163635
The expression //android.widget.ImageView[1]
selects every android.widget.ImageView
that is the first child of its parent. This will in general select a set of nodes. The [3]
selects the third node in this set.
Upvotes: 1