Understanding FindElements in Appium

On This Page By NameBy Class NameBy IDJune 29, 2026 · 5 min read · Tool Comparison

Understanding FindElements in Appium

Appium find elements is one of the most significant skills for mobile automation testers. To run effective test scripts, you must be able to locate UI factor on iOS and Android apps and interact with them just like a real exploiter would. Appium provides two key commands—findElement and findElements—that assist tester identify ingredient by different locator strategy such as ID, name, grade, XPath, and even parent-child relationship.

Overview

How to Find Elements in Appium?

Appium supports multiple locator strategies:

  • By ID– Fastest and most reliable when IDs are unique.
  • By Name– Returns the first ingredient with the specified name, but may gamble duplicates.
  • By Class Name– Locates by grade attribute, often generic.
  • By XPath– Powerful for complex queries but slower and less stable.
  • By Parent Node– Locate parent firstly, then target child elements when no direct ID/Name is available.

What ’ s the Difference Between findElement and findElements?

  • findElement→ Returns a individual element or throw an exception if not establish.
  • findElements→ Returns a list of elements and can be empty if no match be.

Best Practices for Locating Elements in Appium

  • Prefer ID locatorsfor stability.
  • Use XPath or parent-childonly as fallback.
  • Validate onreal devices, not emulators.

This concise guidebook explicate Appium element locators—Name, Class, ID, XPath, Parent—and the dispute between findElement and findElements.

By Name

When situate an element with its name, the program will render the initiatory element with the gens attribute value match the location. If there is no element with a matching name attribute, aNoSuchElementExceptionis thrown.

The ground for mentioning the “ first element ” is that multiple element can have the same gens because the developer chose to use non-unique names or auto-generate the names. In this event, the findElement command will regress the initiatory element that carries the specified name.

Example:

Take the image below.


Image Source

To locate the circled elements by name, use the code below:

driver.findElement (By.name (`` Shop byDepartment '')) .click (); //or driver.findElementByName (`` Shop byDepartment '') .click ();

By Class Name

In this case, an element is place by the value of its form attribute. However, since a class usually contains multiple elements, this strategy go fairly generic in nature. It is not the best way to find a single unique component.

Example:

Take the icon below:

Image Source

To locate the circled element by category name, use the code below:

driver.findElementByClassName (`` android.widget.ImageView '') .click (); //or driver.findElement (By.className (`` android.widget.ImageView '')) .click ();

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

Note: The code will only return efficacious results when there exists a unique class gens. Be warned that this is commonly not the case in Appium.

Try Appium Testing on Real Devices for Gratuitous

By ID

When locating web elements by ID, Appium will return the first element with the jibe ID dimension. In case no element has that matching ID dimension, the program will shed a NoSuchElementException.

Since each element ordinarily tends to receive a unique ID, identifying them with this method is usually the almost dependable and effective locator strategy in Appium script.

Example:

Take the image below:

Image Source

To site the circled ingredient by ID, use the codification below:

WebElement element = driver.findElementById (`` in.amazon.mShop.android.shopping: id/action_bar_burger_icon ''); & lt; br & gt; element.click (); // or WebElement component = driver.findElement (By.id (`` in.amazon.mShop.android.shopping: id/action_bar_burger_icon '')); & lt; br & gt; element.click (); element.click (); // or driver.findElementById (`` in.amazon.mShop.android.shopping: id/action_bar_burger_icon '') .click ();

By XPath

When using Appium findElement by XPath, the program analyzes the XML structure of the app and locates a exceptional element relative to other elements. In fact, originally this strategy was developed to sail XML data in order to locate unique UI elements.

Remember that are not cross-platform. Hence this method should be used for encounter elements solely when there is no gens or ID assigned to a UI element. XPath tends to have performance and stability issues and can be brittle when employed across platforms or even devices.

However, locating elements by XPath also has certain advantages:

  • Allows the formulation of complex inquiry
  • It can be used to find any element in the XML structure available to Appium. This means that even if an constituent has no ID or Name, it can still be locate with XPath

Note: When utilise the for inspecting the application XML structure, Appium will return the XPath straight without extra effort.

Using Parent Node

In certain situations, the only pick is to locate an element by getting the parent element first and then get its youngster aim. This is done to perform an action on the child element.

Example:

Consider the username text box for the Amazon app. TheUserNametext box does not have an ID, text value, or content-desc attach to it. TheclassNameis populated but that execute not facilitate because theclassName of the Passwordschoolbook box will be the same as the exploiter name.

In this lawsuit, one must find a unique parent, which is the Amazon Sign in & # 8211; depicted in the image below:

Image Source

To locate the parent component, use the code below:

WebElement parentElement = driver.findElement (By.name (`` Amazon Sign In ''));

After getting the parent element, one can so get the child element Views which exists under the selected parent. Use the codification below:

List & lt; WebElement & gt; childElements = parentElement.findElements (By.className (`` android.view.View ''));

On getting the Views factor inchildElements,one can farther place the 5th View ingredient. Refer to the image below for clarity:

Image Source

Find the 5th View element with the code below:

//This is to get the 5th tike constituent WebElement mainElement = childElements.get (4);

Note:Mention .get (4) to specify the 5th element because the index starts from zero.

On getting the main ingredient (5th), merely identify it ’ s child ingredient with the codification below:

mainElement.findElements (By.className (`` android.widget.EditText '')) .sendKeys (`` Your_UserName '');

Here ’ s the complete codification:

WebElement parentElement = driver.findElement (By.name (`` Amazon Sign In '')); List & lt; WebElement & gt; childElements = parentElement.findElements (By.className (`` android.view.View '')); WebElement mainElement = childElements.get (4); mainElement.findElement (By.className (`` android.widget.EditText '')) .sendKeys (`` Your_USerName '');

Difference between FindElement and FindElements in Appium

The only difference betweenfindElement and findElementsin Appium is that the initiative bidding returns either a WebElement aim or throw an elision. The latter returns a list of WebElements and can return an empty list if no DOM elements pair the query.

Clear knowledge of how to find elements in Appium iOS and Android is integral to building effective and advanced test scripts. Because of this, all personnel need to be conversant in thefindElement and findElementscommands. Run the code laid out in this article, and start building accurate and result-driven trial rooms for mobile apps.

Tags
31,000+ Views

# Ask-and-Contributeabout this subject with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free