The Agile Way — Practical Automated E2E Testing

The Agile Way — Practical Automated E2E Testing

Basic Appium Automation: Part 3— Using Locators (Android)

How To Use the Accessibility ID, ID, XPath and Class Name Locators in Android

Courtney Zhan's avatar
Courtney Zhan
Jul 29, 2024
∙ Paid

In Part 1, we covered the available locator types in Appium 2. In Part 2, we looked at using locators for iOS. In this article, let’s look at creating a sample script using a few different locator types for an Android app.

Key Points

  • Using the Accessibility ID, ID, XPath and Class Name Locators in a sample Android app

  • Using the find_element method to locate a single element

  • Using thefind_elements method to locate multiple elements with the same locator

Sample App

This article uses Appium’s Sample Android Test App. This is available on Appium’s Github page as a sample app. Download and save the ApiDemos-debug.apk file.

This test app contains a simple addition calculator, which we will use to try out the AccessibilityID, Name, XPath and Class locator types.

Android Calculator App — Accessibility ID, Name, XPath, Class Locators

The Appium capabilities to start up the Appium session are:

app_file = File.join(File.dirname(__FILE__), "..", "..", "sample-apps", "ApiDemos-debug.apk")

opts = {
  caps: {
    automationName: 'UiAutomator2',
    platformName: 'Android',
    platform: 'Android',
    platformVersion: '12',
    deviceName: 'emulator-5554',    
    app: app_file,
    appPackage: 'io.appium.android.apis',
    appActivity: 'io.appium.android.apis.ApiDemos'
  },
  appium_lib: {
    server_url: "http://127.0.0.1:4723"
  },
}

You can copy these into Appium Inspector as well:

The API Demos app features a lot of different Android components. For this demo, we’ll be navigating through the catalog, then showing and hiding a header field.

Let’s look at each section one by and one and identify some locators.

1. App Menu

User's avatar

Continue reading this post for free, courtesy of Zhimin Zhan.

Or purchase a paid subscription.
© 2025 Zhimin Zhan · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture