Search code examples
javaandroidappium

Appium Android How to tap using the TEXT value


I want to play a song by making Appium tap the song name. Is there a code which can allow me to tap any element by using the TEXT field? I cannot use the resource id field here as there will be multiple songs later on. I tried using By.xpath("//android.widget.EditText[@text='"+song name+"']"); but that did not work.

enter image description here


Solution

  • Found the solution. I had to write the following code in my test:

    capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);
    

    Now I can use the TEXT value by writing that song name in the XPath like this:

    By.xpath("//*[@text='" + element + "']");
    

    Here element is the text value shown in UIAutomatiorViewer.