Extract Xpath from App using Macaca Inspector

What is Macaca Inspector?

This is a slick web based inspector created by the Macaca team, that is from the mighty Alibaba Inc. Macaca basically provides a full suites of open source solutions based on Selenium Web Driver, for both Web and mobile. This inspector is just one of the tools.
The tool has the ability to pull Xpath values for Android or IOS.

How to Install Macaca Inspector?

These instructions are under the assumption you have Appium installed locally already with nodeJS, and Android and ANT path is set globally.
NPM command will only work if the NodeJS is installed on the system.  

First you have to instal the nodeJS
1) On windows, Open up CMD and run “npm install macaca-cli -g

npm install


Once the installation is complete, you will see the Successful message.

macaca installation process



2) After install is complete, verify it was installed correctly, run “macaca doctor

macaca path set

Make sure that everything should be green. If anything is Red, you need to install that to your system such as JAVA_HOMEANT_HomeAndroid Path etc.
4) Next, run ”npm install app-inspector -g

npm install app doctor


After install is complete you should see that the words “BUILD SUCCESSFUL” in the logs.

Build successful macaca complete process

5) Connect the device or launch a simulator and grab the DEVICE_ID of the device or simulator by issuing “adb devices”. Please follow the tutorial to learn How to Connect with Android Device.

6) Copy the DEVICE_ID and then run,”app-inspector -u YOUR-DEVICE-ID” Make sure device or simulator is booted first before running. When the process is finished, it will load a new window with the view hierarchy loaded and BRAVO! you now have a app inspector.
Note: For Android you can load any application via adb
  • ” adb install example.apk
  • For simulator ” adb install -s example.apk “

7) Now if you go back to the page that loaded the view hierarchy, hit refresh and the app view will load. If you click on a element in the view, it will highlight where that element corresponds to in the view like below:

extract xpath using macaca via terminal

OR You can select the element from the tree and it will highlight it on the view.  On the right hand side you will see that it will also include the Xpath.
Thanks Post author by QA Nishant Paul

1 comment: