Mobile App Automation Using Element Locators and Implicit Waits

Core Components of a Test Case

  • Import required modules:
from appium import webdriver
  • Define capability settings for the target device and application.
  • Instantiate the driver via webdriver.Remote.
  • Apply implicit wait to improve stability across varying response times.
  • Locate UI elements and perform actions using find-and-act patterns.
  • Verify outcomes with assertions.

Desired Capabilities Overview

Desired cpaabilities configure the test environment. Refer to the official documentation at: htps://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md

Common parameters:

  • android only: Settings applicable solely to Android apps.
  • browserName: Specifies the browser engine when testing web contexts.
  • newCommandTimeout: Max wait time (default 60 s) for new commands before session ends.
  • uuid: Identifier for selecting among multiple connected devices.
  • orientation: Sets screen mode to portrait or landscape.
  • autoWebview: Automatically switches context to web views if present.
  • fullReset vs noReset: Control whether app data is cleared between sessions (noReset retains state).
  • dontStopAppOnReset: Keeps the app running across resets, avoiding fresh launches.
  • skipDeviceInitialization: Bypasses initial setup steps, reducing execution time during bulk runs.

iOS only:

  • bundleId: Unique package identifier for iOS applications.
  • noReset: Retains previous session state; for example, dismisses startup dialogs so they do not reappear.

Locating Elements in Appium

To begin locating elements, set minimal capabilities such as:

{"platformName": "android", "deviceName": "emulator-5554"}

Launch the emulator or physical device, then start the target app (e.g., Xueqiu). Refreshing the Appium session reflects the app’s current UI.

Locator Tools

  1. UIAutomatorViewer

    • Available in Android SDK tools; locate via which uiautomatorviewer.
    • Captures live UI hierarchy from the emulator/device for inspection.
    • When multiple devices are attached, prompts for selection.
  2. Appium Inspector

    • Provides interactive element inspection within Appium Desktop.

Coordinates in mobile UI start at the top-left corner (0,0) extending to the bottom-right maximum. Elements follow the same convention, defined by their bounding box corners.

UIAutomatorViewer simplifies complex hierarchies into a flatter XML view (third button), improving rendering performance while retaining all element visibility.

Implicit Waits

Implicit waits instruct the driver to poll the UI for a configurable duration when searching for elements. If a element is not immediately present, the driver waits up to the specified timeout before throwing an exception, smoothing over transient delays.

Example Test Flow on Xueqiu App

from appium import webdriver

cfg = {
    'platformName': 'Android',
    'platformVersion': '6.0',
    'deviceName': 'emulator-5554',
    'appPackage': 'com.xueqiu.android',
    'appActivity': 'com.xueqiu.android.common.MainActivity',
    'noReset': True,
    'dontStopAppOnReset': True,
    'skipDeviceInitialization': True
}

session = webdriver.Remote('http://localhost:4723/wd/hub', cfg)
session.implicitly_wait(10)

# Open search interface
element_search_tab = session.find_element('id', 'com.xueqiu.android:id/tv_search')
element_search_tab.click()

# Enter keyword into search field
input_box = session.find_element('id', 'com.xueqiu.android:id/search_input_text')
input_box.send_keys('京东')

# Navigate back to home screen (two taps to clear search context)
session.back()
session.back()

session.quit()

Tags: appium Mobile Automation Element Location Implicit Wait Android Testing

Posted on Tue, 19 May 2026 12:34:10 +0000 by shesma