Appium Element Cheat Sheet

Appium Elements Cheat Sheet

This cheat sheet covers essential Appium element commands, from locating elements using different strategies to performing actions like clicking, sending text, retrieving attributes, and executing touch gestures.
 

Command / Action

Description

Example / Notes

Find Element

Locates a single element by locator strategy.

driver.findElement(By.id("com.example:id/button"))

Find Elements

Locates multiple elements by locator strategy

driver.findElements(By.className("android.widget.TextView"))

By ID

Finds element by resource-id or accessibility id

By.id("com.example:id/input")

By XPath

Finds element using XPath expression.

By.xpath("//android.widget.TextView[@text='Login']")

By Accessibility ID

Finds element using accessibility label.

By.accessibilityId("loginButton")

By Class Name

Finds element by Android/iOS class name.

By.className("android.widget.Button")

By Android UIAutomator

Android-specific locator strategy.

MobileBy.AndroidUIAutomator("new UiSelector().text(\"Login\")")

By iOS Predicate

iOS-specific predicate locator.

MobileBy.iOSNsPredicateString("label == 'Login'")

By iOS Class Chain

iOS-specific locator for complex hierarchies.

MobileBy.iOSClassChain("**/XCUIElementTypeButton[`label == 'Login'`]")

Click

Clicks the element.

driver.findElement(By.id("button")).click()

Send Keys

Enters text into input fields.

driver.findElement(By.id(“button”)).sendKeys("Hello")

Clear

Clears existing text from a field.

driver.findElement(By.id(“button”)).clear()

Get Text

Retrieves the visible text of an element.

driver.findElement(By.id(“button”)).getText()

Get Attribute

Retrieves an element’s attribute value.

driver.findElement(By.id(“button”)).getAttribute("content-desc")

Is Displayed

Checks if the element is visible.

driver.findElement(By.id(“button”)).isDisplayed()

Is Enabled

Checks if the element is enabled.

driver.findElement(By.id(“button”)).isEnabled()

Is Selected

Checks if the element is selected (checkbox/radio)

driver.findElement(By.id("button")).isSelected()

Get Tag Name

Returns element’s tag/type name.

driver.findElement(By.id("button")).getTagName()

Submit

Submits a form.

driver.findElement(By.id("button")).submit()

Tap / Touch Action

Simulates touch action (tap, long press, etc.)

new TouchAction(driver).tap(PointOption.point(100, 200)).perform()

Swipe / Scroll

Performs swipe or scroll gestures.

driver.executeScript("mobile: swipe", params)

 

Related Tutorials