How to click on a mobile ojects with similar xpath?

Hi,
I have a problem with my test case. Particurally, in the page under test, I have some mobile objects with a similar xpath.

//hierarchy/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.ImageView[1]

//hierarchy/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[2]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.ImageView[1]

I thought of capturing objects with similar xpath using the id so I could get the total number of objects with similar xpath

MobileDriver driver = MobileDriverFactory.getDriver()
List elements = driver.findElements(By.id(“xxx:id/expandable_view_right_icon”))
int total = elements.size()
println total

I tried to click on the object creating a for loop and modifying the only parameter that differs between the various xpath with an index equal to the total number of objects on the page (index i)

for (int i=1; i<=total; i++) {
TestObject object = findTestObject(“null”)
object.setSelectorValue(SelectorMethod.XPATH, “//hierarchy/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[’"+i+"’]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.ImageView[1]”)
Mobile.tap(object, 30, FailureHandling.STOP_ON_FAILURE)
}
Unfortunately with this solution I can always click on the first element only.
Can you help me please?
Thanks.

  TestObject to = new TestObject()
  to.setSelectorValue(...)

The TestObject documentation is here:

https://docs.katalon.com/javadoc/com/kms/katalon/core/testobject/TestObject.html

I have already used this solution but it doesn’t work

@fabio.rismino.automa,

You can combine those 2 XPATHs into these options:

//hierarchy/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]//android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.ImageView[1]

or

//android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.ImageView[1]