# How to select a mobile element with dynamic index property?

**URL:** <https://forum.katalon.com/t/how-to-select-a-mobile-element-with-dynamic-index-property/54077>\
**Category:** Mobile Testing\
**Tags:** mobile-testing, katalon-studio\
**Created:** [April 22, 2021, 1:55pm UTC](https://forum.katalon.com/t/how-to-select-a-mobile-element-with-dynamic-index-property/54077 "2021-04-22T13:55:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgrandillo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mgrandillo/32/16104_2.png) [@mgrandillo](https://forum.katalon.com/u/mgrandillo)\
**Post date:** [April 22, 2021, 1:55pm UTC](https://forum.katalon.com/t/how-to-select-a-mobile-element-with-dynamic-index-property/54077/1 "2021-04-22T13:55:06Z")

</div>

Hi,

I would like to select an object instance on the mobile app depending on the test case.  
However, the index property changes below for each object instance. One object instance  
is mapped in the object repository. If i want to create a for loop to perform actions on several  
object instances within the mobile app, how can this be achieved without having to add each of the  
object instances in the object repository. Thanks.

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/b/b/bbd07cbe04ef0ac14f796a8cb349d5fc19820b42.png)

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [April 27, 2021, 9:23pm UTC](https://forum.katalon.com/t/how-to-select-a-mobile-element-with-dynamic-index-property/54077/2 "2021-04-27T21:23:32Z")

</div>

Although it is on another topic, maybe the following **idea** might help:

> [@Random function](http://forum.katalon.com/t/random-function/53859/8):
>
> hello @ferrariklersone Add the xpath information of your buttons to a list. I can suggest you a code process like the one below. List\<TestObjects\> randomObjects = Arrays.asList(findTestObject('Path/To/TestObject1'), findTestObject('Path/To/TestObject2'), findTestObject('Path/To/TestObject3')) Random rand = new Random()String randomPath = randomObjects.get(rand.nextInt(randomObjects.size()))WebUI.click(findTestObject(randomPath))

Create a list of xpaths (outside the loop) and then call the appropriate one based on the loop counter.

---

<div class="post-metadata">

**Author:** ![mgrandillo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mgrandillo/32/16104_2.png) [@mgrandillo](https://forum.katalon.com/u/mgrandillo)\
**Post date:** [April 28, 2021, 12:42pm UTC](https://forum.katalon.com/t/how-to-select-a-mobile-element-with-dynamic-index-property/54077/3 "2021-04-28T12:42:11Z")

</div>

If i understand the solution above correctly, creating a list of XPATHS means that you have these objects defined in the Object repository which means this is not dynamic. The number of objects i want to select may differ, so i don’t think this solution is feasible, unless I’m misunderstanding the solution?

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [April 28, 2021, 3:50pm UTC](https://forum.katalon.com/t/how-to-select-a-mobile-element-with-dynamic-index-property/54077/4 "2021-04-28T15:50:56Z")

</div>

No, you do **not** have to create an object in the OR to have the computer “see” the object, but it **does** need to have a means to “see” the objects, and that will be via the xpath. Rather than using the OR, you just create a list of objects in code, such as: `findTestObject('Path/To/TestObject1'), findTestObject('Path/To/TestObject2')` etc.

No OR items, but you do need to state the xpaths so the computer can “see” which elements you want.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [April 29, 2021, 8:19am UTC](https://forum.katalon.com/t/how-to-select-a-mobile-element-with-dynamic-index-property/54077/5 "2021-04-29T08:19:04Z")

</div>

@mgrandillo

Have you tried this?

> **[Parameterize Mobile Test Object](https://docs.katalon.com/katalon-studio/docs/parameterize-mobile-test-object-properties.html)**
>
> Parameterizing Mobile Test Object Properties is only available with the Attributes Selection Method. The benefits of parameterizing mobile test objects are similar to those of parameterizing web test objects. Refer...

---

<div class="post-metadata">

**Author:** ![mgrandillo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mgrandillo/32/16104_2.png) [@mgrandillo](https://forum.katalon.com/u/mgrandillo)\
**Post date:** [April 29, 2021, 3:48pm UTC](https://forum.katalon.com/t/how-to-select-a-mobile-element-with-dynamic-index-property/54077/6 "2021-04-29T15:48:17Z")

</div>

THanks, it worked with the following code

for (int index=1; index\<=numberOfSchedules; index++) {  
MobileTestObject viewGroup = findTestObject(“Object Repository/Home Screen/Camera and Camera Settings/android.view.ViewGroup”)  
viewGroup.setMobileLocatorStrategy(MobileLocatorStrategy.XPATH)  
viewGroup.setMobileLocator("//hierarchy/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.FrameLayout[2]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/androidx.recyclerview.widget.RecyclerView[1]/android.view.ViewGroup["+index+"]")  
Mobile.tapAndHold((viewGroup),2,2)  
}

---

<div class="post-metadata">

**Author:** ![shahzadkhan0971](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/shahzadkhan0971/32/16104_2.png) [@shahzadkhan0971](https://forum.katalon.com/u/shahzadkhan0971)\
**Post date:** [January 4, 2022, 8:23am UTC](https://forum.katalon.com/t/how-to-select-a-mobile-element-with-dynamic-index-property/54077/7 "2022-01-04T08:23:11Z")

</div>

How we can do the same in mobile web browser.  
Means first i want to select all a href and h3 tags elements then select any one randomly from them from google search results page in mobile browser.  
the random() function is working properly in web but not in mobile browser on chrome?  
any suggestion please.
