Interact Block XPath Builder

by Fran T

Version 1 (June 20, 2021)

Download (50 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 something that looks like it'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 another XPath which will be much simpler and easier to work with, and should be much more flexible. It'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 its exact position in the Quick Settings panel, which will be different on different devices, and users can even move them. The 'Build Quick Setting XPath' and 'Test Quick Setting XPath' flows are provided for this special situation. There are also UI differences between Android versions of different manufacturers that this flow will accommodate. Further, 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 will usually identify an exact element, it's also very complex and fragile. The slightest change to the app's UI by the vendor will break this XPath, and it's too specific in the case of Quick Settings tiles. Hopefully these flows will help you utilize the power of XPaths without the large amount of knowledge that often requires.

5.0 average rating from 2 reviews

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

Rate and review within the app in the Community section.