Chapter 4. Finding Elements with Different Locators

Appium has different locators to find elements on the mobile apps that can be used while testing. In this chapter, we will discuss some techniques to find an element for native and hybrid apps using the uiautomator and Appium inspector. To find an element for web-based applications, we will see a Chrome add-on to remotely inspect the web elements.

In this chapter, we will learn the following topics:

  • Finding elements using the Chrome ADB plugin
  • Finding elements using the Safari Develop option
  • Finding elements using UIAutomatorviewer and Appium Inspector
  • Finding elements on mobile apps by id, Name, LinkText, Xpath, cssSelector, ClassName, AccessibilityId, AndroidUIAutomator, and IosUIAutomation

Finding elements for Android web-based apps using the Chrome ADB plugin

To find an element for web apps, we need to install an add-on in order to remotely inspect the web elements. The Chrome browser gives us an ADB (add-on) to access the source code of the mobile apps remotely. You can download it from https://chrome.google.com/webstore/detail/adb/dpngiggdglpdnjdoaefidgiigpemgage?hl=en-GB (Make sure you've installed Chrome Version 32 or later on your desktop.).

Once the add-on is installed, perform the following steps to set up the device for remote debugging:

  1. Go to Settings | About Phone and tap on Build number seven times (assuming that you have Android Version 4.2 or newer). Then, return to the previous screen and find Developer options, as shown in the following screenshot:

    Note

    The preceding step is not the same for all smart phones; if you can't find this option, then search How to enable developer options on Google with your device model.

    Finding elements for Android web-based apps using the Chrome ADB plugin
  2. Tap on Developer options and click on ON in the developer settings (you will get an alert to allow developer settings; just click on the OK button); make sure that the USB debugging option is checked:
    Finding elements for Android web-based apps using the Chrome ADB plugin
  3. Now, go to your desktop Chrome browser (assuming that you've already installed the ADB plugin), click on the ADB plugin icon—which is in the top-right corner of the screen—and click on View Inspection Targets:
    Finding elements for Android web-based apps using the Chrome ADB plugin
  4. Use a USB cable to connect your Android device to the desktop (make sure you've installed the appropriate USB driver for your device). After you connect, you will get an alert on your device to allow USB debugging; just tap on OK.
  5. Open the Chrome browser on your device and navigate to the desired URL (we will open www.google.com).
  6. Once you set up your device for debugging, then the chrome://inspect/#devices page will display all the connected devices along with the open tabs and web views. Make sure Discover USB devices is checked, as shown here:
    Finding elements for Android web-based apps using the Chrome ADB plugin
  7. Now, click on the inspect link to open the developer tools; you will get the following screen. Now, click on the screencast icon, in the top-right corner, to display your device's screen:
    Finding elements for Android web-based apps using the Chrome ADB plugin

Now we can easily inspect elements with Chrome DevTools.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.223.239