Interact Block XPath Builder

by Fran T

Version 7 (December 2, 2023)

Download (4,290 downloads)

This flow allows UI elements to be identified by class, text, and/or ID, like earlier versions of the Interact block before it was changed to use XPaths. As before, globbing (wildcards) is supported for identifying elements by text they contain.

To generate an XPath, simply give the flow any of those three identifiers as before. Often, you only need to know the element's text.

If you also/instead need to provide the element's ID or class, use the Record Interactions or Inspect Layout features of an Interact block in your flow and choose the interaction or element you're interested in. Next, look near the bottom of the XPath that was generated for elements that look like they'll uniquely identify the element. The best choice is ID, followed by element text and/or class. Using as few as necessary, copy those attribute(s) and give them to the XPath Builder flow. It'll generate a much simpler XPath that's copied to your clipboard to make it convenient to paste back into your Interact block.

Here are some sample XPath identifiers to look for to give to this flow:

button[@class="android.widget.TextView"]
-The class is android.widget.TextView

android.view.ViewGroup[@android:contentDescription='Flashlight,Off.,Button']
-The element text is Flashlight, followed by some other stuff we don't want. Here we'd enter "Flashlight*" when prompted for element text

android.widget.FrameLayout[@android:id='@com.android.systemui:id/notification_panel']
-The ID is notification_panel and the app is the System UI

If the element you're interested in is an Android Quick Setting tile (such as Flashlight, Location, etc.) it's much better to use its text to identify it. -The Interact block's Record Interactions feature will inappropriately give you a tile's exact position in the Quick Settings panel, which will be different on different devices and Android versions, and users can move the tiles themselves. The 'Build Quick Setting XPath' and 'Test Quick Setting XPath' flows are provided for this special situation. If you specify the Wi-Fi tile, the flow will generate a special XPath that will work for Samsung One UI, as well as other devices. Your flows will work on many more devices as a result.

The new Interact block no longer allows elements to be specified by their class/text/ID, and its Record Interactions feature now works by generating a full XPath which includes every element from the top of the application's UI element tree down to the desired element. While this can identify an exact element, it's also very complex and fragile. Hopefully these flows will help you utilize the power of XPaths without the large amount of knowledge that requires.

Updates:
o Removed requirement for "read sensitive log data" permission; improved Test flow reliability
o Quick Setting paths simplified and updated for Android 14

4.8 average rating from 20 reviews

5 stars
19
4 stars
0
3 stars
0
2 stars
0
1 star
1
Reports
0

Rate and review within the app in the Community section.