Not able to click all the elements of an array


#1

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?


#2

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


#3

@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.


#4

Define “gets stuck”.

And what does the log say?


#5

@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


#6

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


#7

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


#8

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

#9

Good eyes!


#10

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


#11

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.