Search code examples
androidandroid-studioxpathappiumappium-android

How to write relative xpath for radio button for an element in Mobile App using Appium


I am trying to automate my Mobile APP where I have a scenario to change 2 or more cards. These cards are displayed in radio button and I have to choose among these cards

The absolute xpath for 1st radio button is

/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.ScrollView/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout[1]/android.widget.RadioButton

The absolute xpath for 2nd radio button is

/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.ScrollView/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout[2]/android.widget.RadioButton

There are no other significant properties for this radio buttons to write relative xpath.

How to write relative xpath for this?

Attaching screenshot for the same. Appreciate your response.Thanks in advance.

enter image description here


Solution

  • Try the bellow xpath:

    (//*[contains(@class,'RadioButton')])[2]
    

    The above for second radio button.