Inspecting native apps using appium

To learn the element properties in the app, you will have to inspect the app using UIAutomatorViewer. This tool is available in /Users/admin/Library/Android/sdk/tools/bin directory where you installed Android SDK. This is the default path in Mac. In Windows, that folder is in appdata. Just go to that directory and execute below command.


Uiautomatorviewer &

If above command is successful, you can see the UI Automator Viewer window. Then just open the app in Emulator and then click on small mobile button at the left top bar of UI Automator Viewer. Then it will show you the details of every element in the app. You can hover over the element for which you need to get properties. You can use this information to write the element locators in your appium code.

You may get error saying "Error obtaining UI hierarchy Error while obtaining UI hierarchy XML file" when using UI Automator viewer. In this case, what you can do is get the source code of the app using code as shown in below exmaple.


System.out.println(String.format("XML source %s", driver.getPageSource()));

Web development and Automation testing

solutions delivered!!