Stuck in a screen where I have to tap on relative element of android app

Hello Experts,

I Have a app where I m stuck in ‘Buy Tickets’ screen ,here In this screen there are many passes but out of all these passes i have to tap on one particualr pass, the index and names are unique for these passes, but the ‘+’ button next to all of these passes, they also have index numbers but all have been assigned value of 2, how should i tap on the '+'button (they are named as ‘Add to cart’)
I am attaching the screenshot from uiautomatorviewer for the app with xml ,if an body can just let me know how should i tap on a particular element, Please note the passes are not tappable and only on the ‘+’ button user can tap,

Here is the script:
package androidApp;

import java.sql.Driver;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.remote.MobileCapabilityType;

public class MartaApp {

public void test() throws MalformedURLException

DesiredCapabilities cap = new DesiredCapabilities();

cap.setCapability("app", "/Users/xyz/Downloads/appname.apk");

cap.setCapability("platformName", "android");

cap.setCapability("deviceName", "Nexus 6P");

cap.setCapability("platformVersion", "6.0.1");

cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "100");

AndroidDriver driver = new AndroidDriver(new URL(""),cap);

driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);

driver.findElement("xyzpackagename<img src="/uploads/default/original/2X/5/5a539c64c718a98d023b6f8819f73ff3aee10180.png" width="690" height="397">:id/tileTitle")).click();

//The below code will print whether its native or hybrid view

Set<String> ContextNames = driver.getContextHandles();
for(String contextNames : ContextNames)

/WebElement a= 	 driver.findElementByXPath("//*[@class='android.widget.RelativeLayout'[@text='1-Day Pass'and @index ='2']");;

Does your relative layout has any unique id or xpath.
You can get hold of relative Layout or group which will have Item_price_ADd option.
Then using xPath you can get handle to add

Hello @RamS if you can see the image of UIautomator attached, it shows the relative paths for the element ‘+’ but all ‘+’ button has same index, i want to tap on the ‘+’ button for a specific pass. If you can get the idea from the image itself let me know

I can think of a workaround, as below [Not sure if it really works, need to explore]

Ex :

public final String ONE_DAY_PASS = "//android.widget.TextView[@text='1-Day Pass']";

Then try if you can get the handle to parent relative layout of this. And probably look for “+” inside this relative layout.

I will explore and get back if I find a solution.

Hi RamS,

Finally I am able to tap on the ‘+’ button ,thanks a lot for your suggestion.

If I get stuck somewhere else Il take your advise :slight_smile:

Sure… No problem.

Can u share the solution that worked for u.

Hi @RamS, The problem was that i was not giving a exact xpath ,correct Xpath solved the problem using the appium inspector tool

Thanks a lot

1 Like

Can you advice how did you resolve this? I am trying to click the list items of sidebar drawer which is a Relative Layout. I can locate the layout by its id but unable to locate the list items.

**<Text/Name of the list item>
This resolved my issue.

xpath = "//*[ ./android.widget.TextView[.=\"1-Day Pass\"] ]/ImageView"