Home Appium Environment Setup Android Emulators iOS Simulators Appium Architecture Android chrome app automation Safari browser automation Appium Capabilities Inspecting android apps Native Android app automation Inspecting iOS app Native iOS app Automation Real Android Phone automation Real iPhone automation Element Identification Pressing button FaceId and TouchId Fingerprint automation Drag and Drop Tap and press Swipe gestures Hybrid app automation Execute script Synchronization in Appium Screenshots Page Object Models Cucumber and Appium Appium integration with azure Appium and Selenium Grid Running tests in browserstack Parallel testing Recording tests Mobile automation framework Errors and Exceptions in Appium Mobile automation test strategy Mobile automation challenges Appium QnA
Element identification in appium
You can use below element selector strategies
- XPATH
- ID
- Class Name
- Accessibility ID (XCUITest - accessibility-id attribute and Android - content-desc attribute)
XPATH Examples
If you are familiar with Selenium XPATH expressions, you already know how to write xpath expressions for Appium app elements as well. The syntax is exactly same. You can see XPATH examples here -XPATH Examples.
Below example shows how we can use various identification methods in Appium
package org.softpost.ios.simulator;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.TouchAction;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.touch.offset.PointOption;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.URL;
import java.util.concurrent.TimeUnit;
/**
* Created by Sagar on 10-07-2016.
*/
public class AppiumTestAppTest {
AppiumDriver driver;
@Test
public void testContacts() throws Exception{
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("platformName", "iOS");
caps.setCapability("platformVersion", "11.0");
caps.setCapability("deviceName", "iPhone 8");
caps.setCapability("AutomationName" , "XCUITest");
caps.setCapability("waitForQuiescence" , false);
caps.setCapability("app", "/Users/admin/TestApp.app");
try {
driver = new IOSDriver(new URL("http://0.0.0.0:4723/wd/hub"), caps);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//WebElement e = driver.findElementByAccessibilityId("ComputeSumButton");
//WebElement e = driver.findElementById("ComputeSumButton");
WebElement e = driver.findElement(By.xpath("//*[@name='ComputeSumButton']"));
// e = driver.findElementByTagName("XCUIElementTypeButton");
e.click();
Thread.sleep(2000);
}catch (Exception ex){
ex.printStackTrace();
}finally {
driver.quit();
}
}
}
Web development and Automation testing
solutions delivered!!