Xpath to get text from xml

27 views
Skip to first unread message

norman bond

unread,
May 5, 2026, 7:45:09 AM (3 days ago) May 5
to Automate for Android
Hi, I'm probably making silly mistake but I cannot get his xpath 
to work in Inspect layout block.

xpathEncode(".//*[@android:id=\"@com.gotogames.funbridge:id/result_screen_ranking_header_rank\"]/@android:text")
There is only 1 such entry in the xml layout.
All I get back is the encoded xpath not the text on screen.
Result is set to string

Henrik "The Developer" Lindqvist

unread,
May 5, 2026, 8:28:43 AM (3 days ago) May 5
to Automate for Android
The xpathEncode function is for including text in a XPath predicate as a string, not for the encoding the the whole expression.
Try using just:
.//*[@android:id='@com.gotogames.funbridge:id/result_screen_ranking_header_rank']/@android:text

norman bond

unread,
May 6, 2026, 7:54:28 AM (2 days ago) May 6
to Automate for Android
Thanks.".//*[@android:id=\"@com.gotogames.funbridge:id/cell_result_screen_ranking_player_pseudo\"]/@android:text"
Sorry but a couple more questions.
The app I'm processing has display of one off info at the top followed by a s⁵crollable list of player info.

1) how can I get 2 or more attributes from 1 Inspect. I thought it was just by adding further clauses at the end,
 Eg "/@android:text/@android:layout_y" but returns null.

2) how to process the scroll able list. No predicate or [1] returns the 1st matching data, 
Eg ".//*[@android:id=\"@com.gotogames.funbridge:id/cell_result_screen_ranking_player_pseudo\"]/@android:text"
Or ".//*[@android:id=\"@com.gotogames.funbridge:id/cell_result_screen_ranking_player_pseudo\"][1]/@android:text"
But [2] etc returns null.

I do have a working flow (complex as does process other screens as well) using findall on the layout, but would like t
o use Inspect as a more robust solution

Henrik "The Developer" Lindqvist

unread,
May 6, 2026, 9:28:20 AM (2 days ago) May 6
to Automate for Android
  1. Try using an union expression, e.g. .//android.widget.TextView | .//android.widget.ImageView
  2. It should work, but keep in mind that it usually only include visible items, and that the [1] position predicate reflects the visible index which may not correspond to the actual list position, use the @android:layout_row for that.
    Maybe item [2] had not loaded, yet to be rendered, when the layout was inspected, try using a short Delay to have more items be loaded

norman bond

unread,
May 6, 2026, 11:10:32 AM (2 days ago) May 6
to Automate for Android
Hi.
1) not sure i follow that. I want 2 attributes from the same
 element. I've seen examples in other forums (for different tools)
 shown as /attr1/attr2 after the element path
2) definitely visible on screen, however there is no layout_row
 in the xml so I guess it won't  be possible.

Henrik "The Developer" Lindqvist

unread,
May 6, 2026, 1:52:17 PM (2 days ago) May 6
to Automate for Android
  1. e.g. .//android.widget.TextView/@*[name()='android:text' or name()='android:layout_y'], see here.

norman bond

unread,
May 7, 2026, 6:48:03 AM (yesterday) May 7
to Automate for Android
Thanks,  but that selects an element with either of those 2 attributes. What I was
 looking for getting 2 (or more) attributes from a single element.
I've looked at several forums but none of the suggestions works for me.

Henrik "The Developer" Lindqvist

unread,
12:21 PM (3 hours ago) 12:21 PM
to Automate for Android
No, that should select all attributes /@* with those name()=, ensure Result type is Node-set.
Reply all
Reply to author
Forward
0 new messages