0

How to create Xpath with the help of UIAutomator for android App?

Link to any guide would be very helpful. Currently UIautomator does not gives Xpath. I want to know the steps to create a xpath.

  • You can check out my answer for similar question [here][1] [1]: http://stackoverflow.com/questions/24166821/how-to-determine-the-xpath-of-android-ui-elements-selenium-appium/24202109#24202109 – Vinay Jul 09 '14 at 08:28

3 Answers3

2

Ok so I recommend reading this article: http://www.w3schools.com/XPath/xpath_syntax.asp

But to give you an idea if you wanted to find a TextView with the text "hello world" you could use this xpath:

//android.widget.TextView[@text='hello world']

// means get any element

//android.widget.TextView means get any element with the class android.Widget.TextView

//android.widget.TextView[@text='hello world'] means get any element of class android.Widget.TextView with attribute "text" equal to "hello world"

I hope this explanation helps. If you want a better understanding read that article

dsh
  • 12,037
  • 3
  • 33
  • 51
IWantMoore
  • 73
  • 1
  • 1
  • 10
0

You can access elements form their ID in R.class. For example:

EditText editText = (EditText) getSolo().getView(R.id.note);

You can find it in UIautomator at resource-id column. Also you can click on elements by text and etc.

If you are testing web app, you can emulate view in chrome and get x-path from there. Go to Developer tools -> emulation and select the device and agent that you need.

I was using Robotium framework

and if you don`t know how to build xpath, here is good tutorial http://www.w3schools.com/XPath/

dema_v
  • 71
  • 2
0

It is better to go for appium inspector (appium desktop app) if you are using appium mode, else if in selendroid mode use selendroid inspector - http://selendroid.io/inspector.html

user2220762
  • 565
  • 4
  • 16