Uday
Uday

Reputation: 1484

Need xpath for the country code

Can someone help to find the right xpath for this?

I need to capture the country code, for that i need to identify the element. I tried following xpaths, with no luck.

The linerarlayout at index 1

//[@class='android.widget.LinearLayout' and @index=1]/.//[@resource-id='com.whatsapp:id/country_code' and @index=1]

//[@class='android.widget.LinearLayout' and @index=1]/..//[@resource-id='com.whatsapp:id/country_code' and @index=1]

//[@class='android.widget.LinearLayout' and @index=1]/../[@resource-id='com.whatsapp:id/country_code' and @index=1]

enter image description here

Upvotes: 1

Views: 176

Answers (1)

har07
har07

Reputation: 89315

None of the XPath you posted is valid. Basically, predicate (expression in [] brackets) need to be applied on a context element, for example on a TextView :

//android.widget.TextView[@resource-id='com.whatsapp:id/country_code']

The XPath above will find <android.widget.TextView> element, anywhere in the page, where resource-id attribute value equals "com.whatsapp:id/country_code". Assuming that resource-id attribute is unique, that XPath should be enough to find the target TextView.

Upvotes: 1

Related Questions