Xpath issue in marshmallow

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 kit kat / 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?

is the Android Version 6.0?

Yes the version is 6.0

just stop using slow xPath and start using IDs :slight_smile:

I’m running testing in parallel for those devices, there is no issue with xpath. I think the issue doesn’t come from Android version.

ids, classname, text are not present for some element. so in that case i need to use xpath.

I think the problem is with the view and viewgroup. Till kitkat and lollipop the xpath is showing as view . In marshmallow it is of viewgroup. How to solve this?

i am personally using strategy like:

  • either myself adding IDs into client code
  • i find nearest available element by ID and do now look inside this element.

Make sure you have API level installed in SDK manager for Android 6.0

It is installed. The problem is not with the SDK. If it is the problem with SDK the test wont even get started in the device . But the test is running for all other elements

You was trying to click, tap, or sendKeys on that element?

I m trying to click that element

I found this, can you get the idea and play around for any luck?

Its not able to find the element using xpath. If its found only it is possible to click or send keys to that element. Please suggest me how to find that element

Could you possibly share us the screen from UIAutomator. People will have a chance to give you the correct suggestion.

Ok, from my point of view I would like to suggest (other people can have some better approach one)


  1. Build method: public boolean isMarshmallow to return the boolean to check whether the current device is v6.0
    ref: http://stackoverflow.com/questions/22092118/get-device-information-such-as-product-model-from-adb-command

  2. In POF (page object factory) where you keep element attribution

    For element_X
    //return the xpath with viewGroup
    else {
    //Return the normal one for other Android Version

  3. In test script, when you call the POF, we will have the correct one based on the Mobile is running

@Durga_M : As ScrollView is common irrespective of Android version You can store the items in list and iterate through each.

List<WebElement> items = (List<WebElement>) driver.findElements(By.xpath("//android.view.ScrollView/*"));
    for(WebElement we : items) {
        // write your test logic here

I understand there are 2 scrollViews, so the list will find the first one. I would suggest to check the attributes of scrollView and then re-write xpath accordingly.

1 Like

Thanks… i l try this and update

At the step 01, before applying that approach (to cover any Android v6.0), you can try an simpler solution.
Just need to check the UDID (you already have the Android v6.0’s UDID) and return the expected xpath. once it works, you can try the last approach that I mentioned.

Besides, don’t stop finding out a better one. Discuss around to get some good idea from those who faced that kind of problem.

Hopefully it helps you.

Hi Aleksei,
How you are adding Id’s into code. Basically our application is android Hybird application, in my case also there is no Id’s present for selecting dropdown values. So could you please provide me solution to adding Id’s for List view elements.