It’s time to look at how different elements can be found with Appium and what actually happens on the background when Appium does most of the work for you. This is the 16th tip in our Things You Should Know About Appium and with the following blogs, I’ll be focusing more on Appium commands, how to use them effectively and what tricks may be involved. As always, I’ll provide some code examples for each and every (popular) programming language that is used with Appium.

Android versions 2.3 through 4.2 are supported via Appium’s bundled version of Selendroid, which utilizes Instrumentation. Selendroid has a bit different set of commands than the default Appium, which you need to take into account when targeting both over and under Android 4.2. To access this automation backend, use the automationName capability with the value Selendroid.

Other than the slightly different commands available, the automation backend doesn’t matter much. Appium takes care of running your tests regardless of what OS version will be installed on the device as long as automationName is correctly set.

How to Find Elements with Appium Automation Engine?

Here’s how to find elements with Appium automation engine in use with our Android sample app. The sample app provides a very basic menu-like selection of three items – “Buy 101 devices”, “Use Testdroid Cloud” and “Ask mom for help”. In addition, it provides the similar look-and-feel for both Android and iOS app so the same basic flows can be tried for both platforms. This is how it looks on Appium Inspector as an iOS app under inspection:

The same find strategies work on both Android and iOS as long as the actual attribute values are correct. Here are the examples:

Note that you can find a list of all the elements matching the criteria by using the find_elements_by_ instead of find_element_by_. This list can then be further accessed via index numbers, for example: elems[0].click(). I’ve added the (s) to the examples to show the alternative layout for finding multiple elements.

Using Selenium’s By class (import org.openqa.selenium.By;) can also make things easier in an IDE. Class Byis a mechanism used to locate elements in any document. In order to create your own locating mechanisms, you can subclass this class and override the protected methods as required. Basic examples with By in use: