Understanding FindElements in Appium
On This Page By NameBy Class NameBy IDJune 29, 2026 · 5 min read · Tool Comparison
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. How to Find Elements in Appium? Appium supports multiple locator strategies: What ’ s the Difference Between findElement and findElements? Best Practices for Locating Elements in Appium This concise guidebook explicate Appium element locators—Name, Class, ID, XPath, Parent—and the dispute between findElement and findElements. 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. To locate the circled elements by name, use the code below: 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: To locate the circled element by category name, use the code below: 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 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: To site the circled ingredient by ID, use the codification below: 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: Note: When utilise the for inspecting the application XML structure, Appium will return the XPath straight without extra effort. 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: To locate the parent component, use the code below: After getting the parent element, one can so get the child element Views which exists under the selected parent. Use the codification below: On getting the Views factor inchildElements,one can farther place the 5th View ingredient. Refer to the image below for clarity: Find the 5th View element with the code below: 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: Here ’ s the complete codification: 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. # Ask-and-Contributeabout this subject with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.Understanding FindElements in Appium
Overview
By Name
driver.findElement (By.name (`` Shop byDepartment '')) .click (); //or driver.findElementByName (`` Shop byDepartment '') .click ();
By Class Name
driver.findElementByClassName (`` android.widget.ImageView '') .click (); //or driver.findElement (By.className (`` android.widget.ImageView '')) .click ();
By ID
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
Using Parent Node
WebElement parentElement = driver.findElement (By.name (`` Amazon Sign In ''));
List & lt; WebElement & gt; childElements = parentElement.findElements (By.className (`` android.view.View ''));
//This is to get the 5th tike constituent WebElement mainElement = childElements.get (4);
mainElement.findElements (By.className (`` android.widget.EditText '')) .sendKeys (`` Your_UserName '');
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
Related Guides
Automate This With SUSA
Test Your App Autonomously