By Content-description

Identifying the MobileElement by “Content-description ”. It takes String as an argument. If an element isn't identified it throws an exception as No Such Element Exception.


Here we use the Android Uiautomator method to find the element by using Content-description locator type.

Syntax :

driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR,'UiSelector().description("Locator_Value")')


Content-Description Locator

Example : In the below example we are launching the app on an Android device and clicking on the button using a content-description locator along with the UiSelector() class.

  • Launch the App on an Android device.
  • Click on the button using content-des locator along with UiSelector()
  • Wait for 2 seconds
  • Close the App

ByContentDes.py

from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
import time

# Step 1 : Create "Desired Capabilities"
from selenium.webdriver.common.by import By

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['automationName'] = 'UiAutomator2'
desired_caps['platformVersion'] = '10'
desired_caps['deviceName'] = 'Pixel3XL'
desired_caps['app'] = ('/Skill2Lead/Appium_Demo_App/Android/Android_Appium_Demo.apk')
desired_caps['appPackage'] = 'com.skill2lead.appiumdemo'
desired_caps['appActivity'] = 'com.skill2lead.appiumdemo.MainActivity'

# Step 2 : Create "Driver object"
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)

# Step 3 : Click on the button using content description of the button.
ele_des = driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR,'UiSelector().description("Btn3")')
ele_des.click()

time.sleep(2)
driver.quit()