Site Loader
Auckland, New Zealand
In the last post we discussed locating element using ID and in this post we will start to locate element of Android application using
  • Class Name
  • Accessibility ID
  • ID
Here is the complete code for identifying control using different locators.
public class FirstAppiumTest {

	// Create instance for Appium Driver
	AppiumDriver driver;

	@BeforeClass
	public void Setup() throws MalformedURLException {

		DesiredCapabilities cap = new DesiredCapabilities();
		cap.setCapability(MobileCapabilityType.DEVICE_NAME, "donatello");
		cap.setCapability(MobileCapabilityType.APP_PACKAGE,
				"com.android.calculator2");
		cap.setCapability(MobileCapabilityType.APP_ACTIVITY, "Calculator");
		// cap.setCapability("avd", "Test");

		driver = new AndroidDriver(new URL(
				"http://127.0.0.1:4723/wd/hub"), cap);

	}

	@Test
	public void SimpleTest() {

		// Click 5
		driver.findElementById("digit5").click();
		// Click 5
		driver.findElementById("digit6").click();
		// Click 5
		driver.findElementByAccessibilityId("plus").click();
		// Click 5
		driver.findElementById("digit9").click();
		// Click 5
		driver.findElementById("digit3").click();

		driver.findElementByAccessibilityId("equals").click();

		// Verify the result
		String result = driver
				.findElementByClassName("android.widget.EditText").getText();

		if (result.equals("149"))
			System.out.println("PASSED");
		else
			System.out.println("FAILED");

	}
}

As you can see from the above code, we have also used the getText() method to get the text out from a control and verified if the text is as expected. Here is the complete video for the above discussion Thanks for reading the post and watching the video !!! Please leave your comments and let me know if there is anything I should update in this post. Thanks, Karthik KK

Post Author: Karthik kk

3 Replies to “Locating elements in Appium (Part b)”

  1. Hi Karthik,

    Session was good , but I have real time issue in using “content-desc” value in findelementbyaccessibilityid.
    for emulator “content-desc” value is showing it as “equals” but for real devices , it may show it as “equals button” . This kind of behavior i observed in real time apps particularly for image buttons. Because of this ,scripts written in real devices using accessibility locator strategy are not working in emulator vice-versa.

    you can check app “Safeway” available in Playstore.

    Regards,
    Kiran Edupuganti

  2. Accidentally I visited this site. Good videos. I am into Mobile Automation testing and I would want to keep in contact with you.

Leave a Reply to Kiran Cancel reply

Your email address will not be published. Required fields are marked *