How to get element by xPath

Hi all,

i get stuck with getting below element. in below pic , i try to click on the Gmail image

so my xpath is :
xpath="//android.widget.LinearLayout[0]/android.widget.RelativeLayout[0]/android.widget.RelativeLayout[0]/android.widget.ImageView[0]"

But when i run, the error is : can not be located on the screen. Can anyone show me what wrong with above xpath.

Appriciated your help.

Thanks

Please refer here:

Hopefully it helps you.

Hi TuHuynh,

Thanks for your advice, it works now.

so I changed the xpath from :

xpath="//android.widget.LinearLayout[0]/android.widget.RelativeLayout[0]/android.widget.RelativeLayout[0]/android.widget.ImageView[0]"

to :

xpath="//android.widget.LinearLayout[@index=β€˜0’]/android.widget.RelativeLayout[@index=β€˜0’]/android.widget.RelativeLayout[@index=β€˜0’]/android.widget.ImageView[@index=β€˜0’]"

And it works now.

1 Like

Happy when hearing that works for you.

I think you should read this topic as well. There are something related and may helpful.