How to get unique property or xpath for android native app

Hi,

I working on android native apps using appium and for few elements donot have any unique property to be used so that left me to use only xpath but as you can see in the below screenshot its a long tree hierarchy

So, I want to know is there any way we can use any property or to get the xpath of the element please let me know

Thanks

I’ll claim up front that I’m not the best with XPath, but we use it on our project.

If you don’t mind searching for the text, Perhaps you could do something like this:

xpath = “//android.view.View[@text=‘Economy’]”
appium_driver.driver.find_element(:xpath, xpath)

I far prefer resource-id, but that requires Android 4.3 or later and some effort on the product development side, which may not be available to you.

thanks Willosser,
I have selected the wrong element suppose I want to select Parent View Element i.e (4) View[20,632][700,750] So how could I do it as it donot have any text attribute with it and I am using Android 5.0.2 but in my Application resource Id is blank so not able to use it.

Please let me know if you have any resolution for it

You can use relative paths thorugh xpath if you can identify a node. For example, if you wanted the parent of the Economy android.view.View, you could provide this xpath:
//android.view.View[@text=‘Economy’]/…”

If you wanted the spinner that’s adjacent to the economy view, if you couldn’t address it directly you could use
//android.view.View[@text=‘Economy’]/…/android..Spinner”

ok thanks a lot, I didn’t tried this but if this worked it would be great.