1

I am trying to automate an app . I have found few of the elements using xpath. In marshmallow devices, the elements are not able to find using xpath which is working fine in kitkat/lollipop devices. For example in KitKat/lollipop the xpath contains view; the same xpath in marshmallow instead of view it is taking as Viewgroup. How to provide the same xpath for all the version?

The following are the xpath of the same element in kitkat and marshmallow :

In kitkat: xPath is //android.widget.LinearLayout[1]/android.widget.FrameLayout[‌​1]/android.widget.Fr‌​ameLayout[1]/android‌​.view.View[1]/androi‌​d.view.View[1]/andro‌​id.view.View[1]/andr‌​oid.view.View[1]/and‌​roid.view.View[1]/an‌​droid.support.v4.wid‌​get.DrawerLayout[1]/‌​android.view.View[1]‌​/android.view.View[2‌​]/android.widget.Scr‌​ollView[1]/android.v‌​iew.View[1]/android.‌​widget.ScrollView[1]‌​/android.view.View[1‌​]/android.view.View[‌​1]

In Marshmallow: (for same element xpath is as below) //android.widget.LinearLayout[1]/android.widget.FrameLayout[‌​1]/android.widget.Fr‌​ameLayout[1]/android‌​.view.ViewGroup[1]/a‌​ndroid.view.ViewGrou‌​p[1]/android.view.Vi‌​ewGroup[1]/android.v‌​iew.ViewGroup[1]/and‌​roid.view.ViewGroup[‌​1]/android.support.v‌​4.widget.DrawerLayou‌​t[1]/android.view.Vi‌​ewGroup[1]/android.v‌​iew.ViewGroup[2]/and‌​roid.widget.ScrollVi‌​ew[1]/android.view.V‌​iewGroup[1]/android.‌​widget.ScrollView[1]‌​/android.view.ViewGr‌​oup[1]/android.view.‌​ViewGroup[1]

DDM
  • 113
  • 1
  • 17
  • can you post a piece of code for reference? – Sudharsan Selvaraj Sep 07 '16 at 13:47
  • In kitkat: xPath is //android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.support.v4.widget.DrawerLayout[1]/android.view.View[1]/android.view.View[2]/android.widget.ScrollView[1]/android.view.View[1]/android.widget.ScrollView[1]/android.view.View[1]/android.view.View[1] – DDM Sep 07 '16 at 16:47
  • In Marshmallow: (for same element xpath is as below) //android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.support.v4.widget.DrawerLayout[1]/android.view.ViewGroup[1]/android.view.ViewGroup[2]/android.widget.ScrollView[1]/android.view.ViewGroup[1]/android.widget.ScrollView[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1] – DDM Sep 07 '16 at 16:49
  • Edit the question with the xpath plz. – Bao Tran Sep 12 '16 at 08:21

1 Answers1

0

If you use RELATIVE XPATH your xpath will work for all OS versions.

You are using Absolute xpath which is very bad practice. It is always recommended to use Relative xpath.

You can read more about relative and absolute xpaths here

Community
  • 1
  • 1
Vinod
  • 956
  • 7
  • 15