UIAutomatorViewer Tutorial: Inspector for Android Testing

โšก Smart Summary

UIAutomatorViewer is a graphical inspector bundled with the Android SDK that captures a device screenshot, renders the view hierarchy, and exposes the attributes Appium needs to locate buttons, fields and labels reliably.

  • ๐Ÿ”˜ What it does: Scans a live Android screen and shows the node hierarchy beside a property sheet for the selected element.
  • โ˜‘๏ธ Where it lives: The launcher sits in the Android SDK tools folder as uiautomatorviewer.bat and starts a Java desktop window.
  • โœ… Capture flow: Turn on developer options, attach the handset over USB, then press Device Screenshot to load the current screen.
  • ๐Ÿงช Attribute mapping: text becomes name, resource-id becomes id, class becomes className and content-desc becomes the accessibility id.
  • ๐Ÿ› ๏ธ Troubleshooting: The message “No Android devices were detected by adb” almost always points at a cable, driver or debugging setting.
  • ๐Ÿ“Š Modern option: Appium Inspector covers Android and iOS and remains available after the legacy SDK tools package was retired.

UIAutomatorViewer inspector for Android application testing

What is UIAutomatorViewer?

UIAutomatorViewer is a GUI tool to scan and analyze the UI components of an Android application. To automate any Android application using Appium, a user needs to identify the objects in the AUT (Application Under Test). With UIAutomatorViewer you can inspect the UI of an Android application to find out the hierarchy and view different properties (id, textโ€ฆ) of the element.

While executing automation scripts, Appium uses UIAutomatorViewer to identify different properties of the object and use the properties to identify the required object. That single idea โ€” read the attribute in the inspector, then reuse it as a locator in the script โ€” is what the rest of this page walks through.

The screenshot below shows the tool in its normal working state: the captured device screen on the left, the node tree on the upper right and the property sheet for the selected node underneath it.

UIAutomatorViewer window showing the captured device screen, the node hierarchy tree and the node detail panel

Prerequisites for Using UIAutomatorViewer

The inspector reads the live screen of a real handset or emulator, so a small amount of setup has to be in place before the window will show anything at all.

  • A Java Development Kit: uiautomatorviewer is a Java desktop application started by a batch script, so a JDK must be installed and reachable on the system path.
  • The Android SDK: the viewer ships inside the SDK tools folder, so the SDK has to be installed before the launcher exists on disk.
  • Platform-tools and adb: the viewer talks to the device through the Android Debug Bridge, so adb must be installed and able to see the handset.
  • Developer options and USB debugging: both have to be switched on in the device settings, otherwise adb never lists the device.
  • A data-capable USB cable and driver: a charge-only cable, or a missing manufacturer driver on Windows, produces an empty device list.
  • The application under test: the app has to be installed and open on the device, because the inspector captures whatever is currently on screen.

With those six items in place, the download step is short.

How to Download and Install UIAutomatorViewer

UIAutomatorViewer is a part of the Android SDK manager and will be accessible once you install the SDK manager. Download and install the Android SDK from the official Android Studio download page.

Once the Android SDK is installed, navigate to this path:

c:\users\<username>\AppData\Local\Android\sdk\tools

You will notice a batch file with this name:

uiautomatorviewer.bat

Double click on it to launch the UIAutomatorViewer GUI. The folder listing looks like the one below, with the batch file sitting alongside the other SDK tools.

Android SDK tools folder in Windows Explorer containing the uiautomatorviewer batch launcher

โš ๏ธ Version note: Androidโ€™s own UI Automator legacy documentation still describes launching the tool from <android-sdk>/tools/, but the obsolete standalone Android SDK Tools package is no longer offered by the SDK Manager in current Android Studio releases. Long-standing installations and older SDK archives still contain the launcher; on a fresh installation the file is usually absent, and Appium Inspector is the practical replacement. The original steps above are kept because they remain correct for any machine that still has the tools folder.

How to Use UIAutomatorViewer to Find Objects in Your Application

The capture sequence is always the same: prepare the device, put the screen you care about in front of the camera, then take the snapshot.

  1. Enable developer options on your device. Read Androidโ€™s guide to configuring on-device developer options to see how to enable developer options on Android devices.
  2. Connect your Android device to the PC via a USB cable.
  3. Select the โ€œGuru99โ€ app from the applications list, as shown below.

Guru99 application selected from the Android device application list

  1. Click the Device screenshot button to refresh UIAutomatorViewer and to load the Guru99 application GUI into the tool. The button sits in the toolbar highlighted below.

Device screenshot toolbar button used to refresh the UIAutomatorViewer capture

  1. After the refresh is completed, a screenshot of the Guru99 application opens in the left pane.

Captured Guru99 application screen loaded into the left pane of UIAutomatorViewer

  1. As you see in the above image, on the right side of the window there are 2 panels.

The upper panel contains the node hierarchy โ€” the way the UI components are arranged and contained. Clicking each node gives the properties of that UI element in the lower panel.

  1. Select the โ€˜Quizโ€™ button in the above image to view its different properties (text, resource-idโ€ฆ).

Quiz button selected in the node tree with its properties listed in the lower detail panel

How to Use These Properties to Identify Elements for Automation

Well, you cannot use the properties directly โ€” each property has another name in the automation API. Let us see how to put those property values to work. The following attributes can be used to identify the โ€˜Quizโ€™ button in the Guru99 app.

Attribute in UIAutomatorViewer Locator name in the script Typical use
text name Visible label on a button or a static field
resource-id id The most stable choice when the developer sets one
class className Selecting a group of widgets of the same type
content-desc accessibility id Cross-platform locator that also helps screen readers

Each mapping is visible directly in the node detail panel. The text attribute can be used as โ€œnameโ€, as the property row below shows.

Node detail row showing the text attribute value used as the name locator

The resource-id attribute can be used as โ€œidโ€.

Node detail row showing the resource-id attribute value used as the id locator

The class attribute can be used as โ€œclassNameโ€.

Node detail row showing the class attribute value used as the className locator

The content-desc attribute can be used as โ€œAccessibilityIdโ€.

Node detail row showing the content-desc attribute value used as the accessibility id locator

Along with the above attributes, we can write XPaths for object identification. Those attribute names are also what you pass through desired capabilities and locator strategies once the script is running.

How to Build XPath Locators from UIAutomatorViewer Attributes

XPath is the fallback when no single attribute is unique on its own. The node detail panel gives you every value the expression needs, so an XPath is really just the attribute you already read, written in predicate form.

Work through the panel in this order:

  1. Select the node in the upper panel and read its class, text, resource-id and content-desc values in the lower panel.
  2. Prefer a single stable attribute. If resource-id is populated, use it and stop โ€” no XPath is needed.
  3. If nothing is unique, combine two attributes in one predicate.
  4. If the label changes at runtime, switch the equality test for a partial match.

The patterns below use the attribute names exactly as UIAutomatorViewer reports them.

<!-- match on the visible label -->
//*[@text='Quiz']

<!-- match on the resource-id reported by the viewer -->
//*[@resource-id='com.example.app:id/quiz_button']

<!-- match on the widget class -->
//android.widget.Button[@text='Quiz']

<!-- partial match when the label is dynamic -->
//*[contains(@text,'Qui')]

<!-- two attributes combined for a unique match -->
//*[@class='android.widget.Button' and @content-desc='Quiz']

A few rules keep these expressions from turning brittle. Absolute paths that walk the whole tree break the moment a developer wraps a layout in one more container, so start every expression with the double slash and match on an attribute instead. Index-based predicates behave the same way โ€” they survive until the screen gains a row. And an expression that is unique on a phone screen may match several nodes on a tablet layout, so re-inspect the same screen on both form factors before promoting the locator into a suite. The same discipline applies to XPath in Selenium, where the tree is a DOM rather than a view hierarchy.

Errors One Might Encounter While Using UIAutomatorViewer

Most failures happen before a single node is drawn, and nearly all of them come back to the connection between the workstation and the handset.

  • I see the error โ€” โ€œNo Android devices were detected by adbโ€ โ€” as shown in the screenshot below. How can I resolve this?

UIAutomatorViewer dialog reporting that no Android devices were detected by adb

Solution: Make sure your device is connected to the PC.

The table below extends that answer to the other messages testers hit most often.

Symptom Likely cause Fix
No Android devices were detected by adb Device not attached, USB debugging off, or a charge-only cable Reconnect with a data cable, enable USB debugging, then confirm the handset appears in the adb device list
Device listed as unauthorised The RSA fingerprint prompt was never accepted on the handset Unlock the screen, reconnect and tap Allow USB debugging
uiautomatorviewer.bat is missing The obsolete SDK tools package is not installed Use an existing SDK installation that still contains it, or switch to Appium Inspector
The hierarchy is empty or the capture fails The screen changed during the dump, or the app blocks screen capture Hold the screen still and take the snapshot again; secure screens cannot be captured
WebView content shows as a single node The viewer reads native views only Inspect web content with browser developer tools or an inspector that supports web context

UIAutomatorViewer vs Appium Inspector vs Layout Inspector

Three inspectors are commonly used against Android screens, and they solve slightly different problems.

Criterion UIAutomatorViewer Appium Inspector Android Studio Layout Inspector
Ships with The legacy Android SDK tools package A standalone desktop application Android Studio
Platforms inspected Android only Android and iOS Android only
Needs a running server No, it talks to adb directly Yes, it connects to an Appium server session No, it attaches to a debuggable process
Generates locator code No, values are copied by hand Yes, it suggests locators and can record actions No, it is a debugging view
Best suited to A quick attribute lookup on an older setup Building and validating locators for a suite Diagnosing layout and rendering problems

For a suite that already runs through Appium, the Inspector is the natural successor: it reads the same attributes, runs the same UiAutomator2 driver underneath, and works against iOS as well. The Appium Inspector project is actively released, so it is the safer choice for new work, while Layout Inspector stays useful when the question is why a view renders oddly rather than how to address it. If you are still choosing a stack, the wider comparison in our guide to mobile app testing tools is a good next step, and sample mobile test cases show what these locators eventually feed into.

FAQs

Only partially. The viewer reads the native view hierarchy, so a WebView usually appears as one opaque node. Inspect the HTML inside it with browser developer tools, or use an inspector that can switch into the web context.

No. The tool is bound to the Android Debug Bridge and the Android view hierarchy. For iOS screens use Appium Inspector or Xcodeโ€™s accessibility inspector, which read the XCUITest element tree instead.

The command writes the same hierarchy to an XML file on the device, with no graphics. It is useful in scripts and on headless machines, but you lose the screenshot overlay that makes finding the right node fast.

Machine-learning locator engines score several attributes together โ€” text, class, position and neighbouring nodes โ€” and re-resolve the element when one of them changes. That self-healing behaviour reduces failures caused by a renamed id.

Yes. Paste the attribute values into a comment and Copilot will usually draft the matching page-object field and click method. Always verify the generated locator against the live screen, because the suggestion is a guess, not a lookup.

No. The viewer works against the installed build on the device, so an APK you did not compile can still be inspected. Only attributes the developer actually set, such as resource-id and content-desc, will be populated.

Yes. An emulator appears to adb exactly like a physical handset, so the Device Screenshot button captures it the same way. Emulators are convenient for early scripting, though final runs belong on real hardware.

It gives each control a stable, language-independent handle that doubles as the accessibility id in a script and as the label a screen reader announces. Test reliability and accessibility improve from the same one-line change.

Summarize this post with: