AppiumLibrary is a Mobile App testing library for Robot Framework.

Locating or specifying elements

All keywords in AppiumLibrary that need to find an element on the page take an argument, either a locator or a webelement. locator is a string that describes how to locate an element using a syntax specifying different location strategies. webelement is a variable that holds a WebElement instance, which is a representation of the element.

Using locators

By default, when a locator is provided, it is matched against the key attributes of the particular element type. For iOS and Android, key attribute is id for all elements and locating elements is easy using just the id. For example:

Click Element    id=my_element

New in AppiumLibrary 1.4, id and xpath are not required to be specified, however xpath should start with // else just use xpath locator as explained below.

For example:

Click Element    my_element
Wait Until Page Contains Element    //*[@type="android.widget.EditText"]

Appium additionally supports some of the Mobile JSON Wire Protocol locator strategies. It is also possible to specify the approach AppiumLibrary should take to find an element by specifying a lookup strategy with a locator prefix. Supported strategies are:

Strategy Example Description Note
identifier Click Element | identifier=my_element Matches by @id attribute
id Click Element | id=my_element Matches by @resource-id attribute
accessibility_id Click Element | accessibility_id=button3 Accessibility options utilize.
xpath Click Element | xpath=//UIATableView/UIATableCell/UIAButton Matches with arbitrary XPath
class Click Element | class=UIAPickerWheel Matches by class
android Click Element | android=UiSelector().description('Apps') Matches by Android UI Automator
ios Click Element | ios=.buttons().withName('Apps') Matches by iOS UI Automation
nsp Click Element | nsp=name=="login" Matches by iOSNsPredicate Check PR: #196
chain Click Element | chain=XCUIElementTypeWindow[1]/* Matches by iOS Class Chain
css Click Element | css=.green_button Matches by css in webview
name Click Element | name=my_element Matches by @name attribute Only valid for Selendroid

Using webelements

Starting with version 1.4 of the AppiumLibrary, one can pass an argument that contains a WebElement instead of a string locator. To get a WebElement, use the new Get WebElements or Get WebElement keyword.

For example:

@{elements}    Get Webelements    class=UIAButton
Click Element    @{elements}[2]