Android Automation : How to inspect WebViews and get locators

There are several ways to inspect and build locators of native components in  android application – That can be used with a number of android automation tools . e.g Robotium , Appium etc.  UIAutomatorviewer, Hierarchyviewer to name a few.

When question comes about WebViews , we have a limited number of options. So here a Step by step procedure to get locators/inspect web elements in an android application, using Google Chrome browser on PC.

1. Open an Emulator having android version 4.3+

2. Install the application to the Emulator and open the WebView that we want to inspect.
WebView
Please Note: The activity having WebView must be the front most one.

3. Open Google Chrome(30+) in PC and navigate to “chrome://inspect”.
WebViewChrome
4. Check “Discover USB devices”.

5. Wait a while ! Now you can see the WebView page getting listed under the device/Emulator name along with an inspect button.
WebViewChrome
6. Click on the inspect button and you will get the complete HTML code base of the particular WebView which is on the screen of the Emulator.

7. Build your Xpath etc according to the HTML code, on mousehovering tags you can see the respective elements getting highlighted in the application itself.

both