This lecture helps in understanding the mobile testing
Size: 47.16 KB
Language: en
Added: Oct 24, 2025
Slides: 11 pages
Slide Content
UNIT 3
What are Appium Locators? Locators are references or identifiers used to interact with elements in a user interface (UI).
7 Locator Strategies Supported by Appium ID Class Name Xpath Accessibility ID Android UI Automator Android View Tag (Espresso Only) iOS UI Automation
1. ID Each element has a unique ID assigned to it that helps identify and interact with it. driver.findElementById (" IntegerA "); // for iOS dr.findElement (By.id(" android:id /text1")).click(); //for Android
2. Accessibility ID in Appium Accessibility ID can be used for cross-platform automation, the code becomes reusable. dr.findElementByAccessibilityId ("Accessibility").click();
3. Class Name In the case of Android, the Class Name is called out as the full name of the UIAutomator2 class. For example – android.widget.TextView List< WebElement > buttons = driver.findElementsByClassName (" android.widget.TextView "); for( WebElement button : buttons){ System.out.println ( button.getText ()); if( button.getText ().equals("Animation")){ button.click (); } }
4. XPath Xpath should only be used when there is no ID, Name, or accessibility ID assigned to a specific UI element. XPath allows for the formulation of complex queries. MobileElement computeSumButton = driver.findElementByXPath ("(// XCUIElementTypeButton )[1]");
5. Android UI Automator (UI Automator 2) In Appium, one must send the Java code as a: string to the server executed in the application’s environment, which returns the particular elements. String selector = "new UiSelector ().text(“Cancel”)) . className (“ android.widget.Button ”))"; MobileElement element = ( MobileElement ) driver.findElement ( MobileBy.AndroidUIAutomator (selector));
Which Locator is fastest in Appium? In Appium, the fastest locator strategy is typically the ID.
How do you Inspect Locators in Appium? 1. Appium Inspector : It displays the app’s interface and provides details like IDs, Accessibility IDs, XPath, and other relevant attributes for identifying elements. 2. UI automator view (for Android) / Accessibility Inspector (for iOS): Android and iOS have their own official tools for element inspection.
Advantages of Using Locators in Appium Cross-Platform Support: Flexibility: Improved Test Coverage: Test maintainability Support for Real Devices and Emulators: