Not able to click all the elements of an array

Hi,

I am not able to click all the elements of an array list.Please find the below code:-

elementlist = driver.findElements(MobileBy.xpath("//android.widget.TextView[@text=‘ABC’]"))

elementcount = elementlist.size()

for (def i=0; i<=elementcount; i++)

{

elementlist.get(i).click()

Mobile.pressBack()

}

In the above code the elementcount is 2. I am able to click the element only once.
The code get stuck at elementlist.get(i).click() in 2nd attempt. It does not go further.

Can someone tell me what is the reason that code is not getting executed 2nd time?

Try

elementlist.get(i).click()
Mobile.delay(1)
Mobile.pressBack()
Mobile.delay(1)

You might also want to make sure your elements are visible first (but maybe you already are in code you’re not showing?)

@Russ Thomas:- It does not work even after inserting delay statement.
The code get stuck at elementlist.get(i).click() in 2nd attempt. It does not go further.

Define “gets stuck”.

And what does the log say?

@Russ Thomas:- The code doesn’t traverse through elementlist.get(i).click() in 2nd attempt. It remains on the same line.
Please find the attached screenshots of Logviewer, Console and Appium log for your reference.

Logviewer.PNG

Console1.PNG

Appiumlog.PNG

If the first item in the list works, then I think you’ve found a bug.

@Russ Thomas :- Bug in Katalon or in my native mobile app ?

I found a bug in your test case.

You have this:

for (def i=0; i<=elementcount; i++)

<= is wrong. You should write:

for (def i=0; i < elementcount; i++)

Good eyes!

@kazurayam:- Still it does not work with for (def i=0; i < elementcount; i++). I am still facing the same problem.
Any solution?

I suppose that some state change occurs in the target HTML DOM when

elementlist.get(0).click()

is executed, and that change may cause the following code “stucks”

elementlist.get(1).click()

I have no more words to say.