Aalok
Katalon Apprentice
06/12/2018

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?
Upvote
Quote

Comments

  • Russ Thomas
    Katalon Expert
    06/12/2018
    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?)



    Upvote
    Quote
  • Aalok
    Katalon Apprentice
    06/12/2018
    @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.
    Upvote
    Quote
  • Russ Thomas
    Katalon Expert
    06/12/2018
    Define "gets stuck".

    And what does the log say?
    Upvote
    Quote
  • Aalok
    Katalon Apprentice
    06/12/2018
    @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
    Upvote
    Quote
  • Russ Thomas
    Katalon Expert
    06/12/2018
    If the first item in the list works, then I think you've found a bug.
    Upvote
    Quote
  • Aalok
    Katalon Apprentice
    06/13/2018
    @Russ Thomas :- Bug in Katalon or in my native mobile app ?
    Upvote
    Quote
  • kazurayam
    Katalon Expert
    06/13/2018
    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++)
    Upvote
    Quote
  • Russ Thomas
    Katalon Expert
    06/13/2018
    Good eyes!
    Upvote
    Quote
  • Aalok
    Katalon Apprentice
    06/14/2018
    @kazurayam:- Still it does not work with for (def i=0; i < elementcount; i++). I am still facing the same problem.
    Any solution?
    Upvote
    Quote
  • kazurayam
    Katalon Expert
    06/14/2018
    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.
    Upvote
    Quote
Sign In or Register to comment.