Interact Block XPath Builder

by Fran T

Version 2 (February 7, 2022)

Download (1,045 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:

-The class is android.widget.TextView

-The element text is Flashlight, followed by some other stuff we don't want. Here we'd enter "Flashlight*" when prompted for element text

-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.

o Remove getting clipboard contents from Test flow so Automate doesn't mis-report that the "read sensitive log data" permission is required; improve Test flow reliability

5.0 average rating from 7 reviews

5 stars
4 stars
3 stars
2 stars
1 star

Rate and review within the app in the Community section.