How to get the full xpath of android for to use this xpath to find the next text view of xpath

How to get the full xpath of android for to use this xpath to find the next text view.

Ex. Data on mobile screen A
1. AAAA 50%
2. BBBB 30%
3. CCCC 20%

Ex. Data on mobile screen B
1. AAAA 30%
2. BBBB 30%
3. CCCC 40%

xpath of AAAA ;
//hierarchy/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.widget.ScrollView[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[3]/android.view.ViewGroup[2]/android.view.ViewGroup[2]/android.widget.TextView[1]

xpath of 50% ;
//hierarchy/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.widget.ScrollView[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[3]/android.view.ViewGroup[2]/android.view.ViewGroup[3]/android.widget.TextView[1]

I thing solution to this way

def k1 = xpath of AAAA

def k2 = k1.substring(0,482)

def k3 = (k1.substring(482,483) as int)+1

def p1 = k2+k3+‘]/android.widget.TextView[1]’

But I can’t to the hard code the full xpath. Because of data on screen is dynamic and i can’t get the full xpath for the used sub string function.

Currently I find xpath’s AAA by text

def getXpathDefind(String texts){

TestObject myObject = findTestObject(‘Object Repository/Text’,[(‘text1’): texts])

return myObject

}

pic01.jpg

The 2 expressions has a common prefix:

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

And you mentioned:

Because of data on screen is dynamic …

Do you mean any portion of the common prefix changes dynamically?

If you are happy with the XPath to select ‘AAA’ by @text attribute, then you can use the following xpath in order to reach to “50%” or “30%”:

//*[@text="${text1}"]/parent::android.view.ViewGroup/following-sibling::android.view.ViewGroup[1]/android.widget.TextView[1]

Here I use XPath axes (parent::, following-sibling::, child::).
See https://www.w3schools.com/xml/xpath_axes.asp

Sorry I did not elaborate, I need to get attribute values ​​to check if this percentage is correct or not.Ex.When the answer of 3 question then application will provide model to user.User 1 : 1. A, 2. A, 3. A --> Provide model CUser 2 : 1. A, 2. A, 3. B --> Provide model DModel C1. AAAA                    50%
2. BBBB                    30%
3. CCCC                   20%Model D1. AAAA                    30%
2. BBBB                    30%
3. CCCC                   40%I will to create automate script to check percentage is correct or not.

Did the xpath expression I proposed worked for you, or not?

I need to get attribute values ​​to check if this percentage is correct or not.

Then, what is your current question?

This worked for me. Thanks a lot…