findAll() after PAGE_DOWN does not work

Asked by Scott

I am accessing a long webpage that has several checkboxes. I use findAll() to find boxes that are unchecked, then iterate the findAll enumerator to pull found objects into an array and that works great! However, when I page down and repeat the process it doesn't work. It seems the original findAll() enumerator info is not refreshed. I have used destroy() and set variables to nil, but it still acts on the first findAll() information. I am using Ruby/Sikuli/MAC OS 10.9.5:
def sortIcons
    icons = findAll(image)
    @mm = []
    while icons.hasNext()
        @mm << icons.next()
    end
    icons.destroy() #this apparently does nothing
    icons = nil #or this
    @mm.sort! { |a,b| a.getY() <=> b.getY() }
    doHover
end

def doHover
    @mm.each do |i|
        hover(i) #more processing here....
    end
    @mm = nil
end

i = 0
while i < 2 #loop more times after condition test
    sortIcons
    type(Key.PAGE_DOWN)
    i += 1
end

Thank you,
Scott

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

a findAll() ALWAYS returns a new iterator when called.

Your problem might be timing:
after the issue of the PageDown, the findAll() immediately starts and the first thing it does is to make a screenshot to find the target images in that shot.

I guess this happens so fast, that the page itself is not yet scrolled down.

So after the
type(Key.PAGE_DOWN)

just insert a
wait(1)
# adjust the time to the minimum needed or use any other hack, to wait for the end of scrolling

to give time to the webpage to finish scrolling

Revision history for this message
Scott (scottquote) said :
#2

Yep! That was it. Thank you for answering my question so fast.
Scott

Revision history for this message
Scott (scottquote) said :
#3

Thanks RaiMan, that solved my question.