Appium Python Client

5.3.0 · active · verified Thu Apr 09

The Appium Python Client is a client library for Appium, a mobile automation framework that allows testing of native, hybrid, and mobile web apps. It wraps standard Selenium WebDriver commands to provide Appium-specific extensions for mobile gestures and functionalities. The current version is 5.3.0, and it maintains a frequent release cadence, often addressing bug fixes and minor enhancements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to connect to an Appium server, define basic Android capabilities using `AppiumOptions`, initialize the `webdriver.Remote` instance, and perform a simple element interaction (finding and clicking an element by accessibility ID). Ensure the Appium server (Node.js) is running before executing this script. Environment variables are used for flexibility, with sensible defaults.

import os
from appium import webdriver
from appium.options.common.base import AppiumOptions
from appium.webdriver.common.appiumby import AppiumBy

APPIUM_SERVER_URL = os.environ.get('APPIUM_SERVER_URL', 'http://localhost:4723')

options = AppiumOptions()
options.platformName = os.environ.get('APPIUM_PLATFORM_NAME', 'Android')
options.automationName = os.environ.get('APPIUM_AUTOMATION_NAME', 'UiAutomator2')
options.deviceName = os.environ.get('APPIUM_DEVICE_NAME', 'Android Emulator')
options.appPackage = os.environ.get('APPIUM_APP_PACKAGE', 'com.android.settings')
options.appActivity = os.environ.get('APPIUM_APP_ACTIVITY', '.Settings')

print(f"Connecting to Appium server at: {APPIUM_SERVER_URL}")
print(f"Using capabilities: {options.to_capabilities()}")

driver = None
try:
    driver = webdriver.Remote(APPIUM_SERVER_URL, options=options)
    print("Driver initialized successfully.")

    # Example action: Find and click 'Display' setting
    # Requires an Android emulator/device with the default Settings app
    el = driver.find_element(AppiumBy.ACCESSIBILITY_ID, "Display")
    print(f"Found element: {el.text}")
    el.click()
    print("Clicked 'Display' setting.")

except Exception as e:
    print(f"An error occurred: {e}")
finally:
    if driver:
        driver.quit()
        print("Driver quit.")

view raw JSON →