Finding and Interacting with Elements
Get ready to learn more about Finding and Interacting with elements. Let us begin by understanding various strategies.
In order to learn more about the process of finding and interacting with elements, we start by understanding WebDriver locator strategies. In this case, Appium supports a subset of the WebDriver locator strategies including –
- First, find by “class” (i.e., ui component type)
- Second, find by “xpath” (i.e., an abstract representation of a path to an element, with certain constraints)
Selector Strategies
Some of the popular selector strategies include –
- Accessibility ID
- Class name
- ID
- Name
- XPath
- Image
- Android UiAutomator (UiAutomator2 only)
- Android View Tag (Espresso only)
- Android Data Matcher (Espresso only)
- IOS UIAutomation
Mobile JSON Wire Protocol locator strategies
Further, Appium additionally supports some of the Mobile JSON Wire Protocol locator strategies –
- -ios predicate string : It is a string corresponding to a recursive element search using the iOS Predicate
- -android uiautomator: It is a string corresponding to a recursive element search using the UiAutomator Api (Android-only)
- -android datamatcher: It a string corresponding to an Espresso DataMatcher json (Android-only)
- accessibility id: It is a string corresponding to a recursive element search using the Id/Name that the native Accessibility options utilize.
Additional experimental locator strategies include,
- -image: a string corresponding to a base64-encoded version of an image which should be used by Appium as a template to find a matching screen region, which can then be tapped as if it were an element.
- -custom: a string which will be sent to an element finding plugin registered via the customFindModules capability.
Using Appium Desktop
Appium offers a neat tool that allows you to find the the elements. Together, with Appium Desktop you can find any element and its locators by either clicking the element on the screenshot image, or locating it in the source tree. Additionally, Appium Desktop has a simple layout, complete with a source tree, a screenshot, and record and refresh buttons, and interaction tools.