How to select a mobile element with dynamic index property?


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.

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

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

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?

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.


Have you tried this?

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”)

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.