Could anybody please explain how to find the XPath of an UI element

Hi there, I’m coming from Selenium automation and just got started with Appium so please be patient with me.

For Selenium, I can find the XPath of an element with browser tools. It is not clear to me, how to do this with Appium.

Could anybody please explain how to find the XPath of an UI element for Appium.

Thanks in advance.

Open inspector, navigate over the elements in the appium app and look into the xpath field :slight_smile: .

with help of class name and text attribute… format is “//class[@‘text attribute’]”;

It might be greatly beneficial to you to learn how to write XPaths on your own. I learnt how to search with XPath by looking at examples. Some of the examples on W3C Schools are decent. The XPath specification isn’t really great (IMO) for learning how to use XPath, but it’s good to keep around for reference when needed.

Hi Alex! Thank you for your reply.

I have been doing Selenium test automation for some years now and I think that I’m quite familiar with XPath (and CSS). However, the thing is that for me, the XPaths in Appium look very different from the XPaths in Selenium. For example, in Appium, I see something like this.

By.XPath("//android.widget.RadioButton[@text='Use Testdroid Cloud']")

For Selenium, I can use for example Firebug in Firefox to extract the XPath of an element. I don’t know yet, how to do the same for Appium.

If you throw the test from the appim application, you can open the inspector.

From there you can navigate over all the elements in the screen and look in the xpath field. This xpath is the same as appium understand…

I hope this helps you, I always look the xpaths in this way and is so useful

1 Like

Thank you for your reply. I cannot get the Inspector to run on my system. I was thinking that there are maybe other tools available.

Hmm… I never really used the XPath extraction feature from Appium, since I never needed to do anything with XPath that I couldn’t put together myself. The tool I use the most when I need to do XPath work is uiautomatorviewer itself. This is a tool that should come along with a standard Android SDK installation.


Interesting. I didn’t know this one. Thanks for your suggestion.