scroll down a page with findAll list

Asked by Marc Summers

This is my basic code so far:

What I am trying to do is scroll down a long page of
Buttons, click the button and look for an order code number
in the pop up window. Then close the pop up window
and go to the next button and click it, and so on ....

The code below works OK for only those buttons that
are on screen initially. The problem is if I try scrolling
and then do another list(findAll all of the positions
of the buttons are shifted, and Sikuli clicks but in the
wrong position.
Any help you can give me would be much appreciated.
Thanks.

tbutt = 0

tbuttons = list(findAll("morebutton.png"))
print "I Found ",len(tbuttons)," matches"
tbuttsorted = sorted(tbuttons,key=lambda m:m.y)

for tbutt in tbuttsorted:
    print "Going to click this more button"
    hover(tbutt)

    mouseDown(Button.LEFT)
    mouseUp(Button.LEFT)

    sleep(1)

    try:
        find(Pattern("ordercodedmg290.png").similar(0.99))
        print "Found Order Code DMG290"
        print "I am going with this one ", tbutt
        mouseDown(Button.RIGHT)
        mouseUp(Button.RIGHT)
        mouseDown(Button.LEFT)
        mouseUp(Button.LEFT)

        break
    except FindFailed:
        print "Did NOT Find Order Code DMG290"
        print "Going to try the next more button"

        mouseDown(Button.RIGHT)
        mouseUp(Button.RIGHT)
        mouseDown(Button.LEFT)
        mouseUp(Button.LEFT)

hover(tbutt)

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Marc Summers
Solved:
Last query:
Last reply:
Revision history for this message
TestMechanic (ndinev) said :
#1

I do not see where is your second findAll. Your first findAll is outside the loop.
So you are never updating find result after the first page

Revision history for this message
Marc Summers (2aircraft) said :
#2

I tried a second findAll at the bottom of the loop after the
print "Going to try the next more button"

but I could not get it to work.

I was hoping that you had a suggestion as to
how to insert the second findAll ?

Revision history for this message
TestMechanic (ndinev) said :
#3

Post the new code here. Unfortunately even if we get this right I am guessing one more problem :-). But lest go step by step ...

Revision history for this message
Marc Summers (2aircraft) said :
#4

This is what I tried, but the problem is that
it acts like the first list from findAll is still
there, meaning that the findAll outside the loop
the first one that runs, sets up a list, but the
second findAll inside the for loop, does not appear
to overwrite the first one, so when I try to click the
more button, it is clicking in the wrong place.
I also tried tbuttsorted = 0 trying to clear the
sorted list, but that did not work either.

tbutt = 0
tbuttons = list(findAll("morebutton.png"))
print "I Found ",len(tbuttons)," matches"
tbuttsorted = sorted(tbuttons,key=lambda m:m.y)

for tbutt in tbuttsorted:
    print "Going to click this more button"
    hover(tbutt)
    mouseDown(Button.LEFT)
    mouseUp(Button.LEFT)
    sleep(1)
    try:
        find(Pattern("ordercodedmg290.png").similar(0.99))
        print "Found Order Code DMG290"
        print "I am going with this one ", tbutt
        mouseDown(Button.RIGHT)
        mouseUp(Button.RIGHT)
        mouseDown(Button.LEFT)
        mouseUp(Button.LEFT)
        break
    except FindFailed:
        print "Did NOT Find Order Code DMG290"
        print "Going to try the next more button"
        mouseDown(Button.RIGHT)
        mouseUp(Button.RIGHT)
        mouseDown(Button.LEFT)
        mouseUp(Button.LEFT)

        sleep(5)
        tbuttons = list(findAll("morebutton.png"))
         print "I Found ",len(tbuttons)," matches"
         tbuttsorted = sorted(tbuttons,key=lambda m:m.y)
         sleep(5)

hover(tbutt)

Revision history for this message
Manfred Hampl (m-hampl) said :
#5

Which part of your code should result in scrolling down to the next page?

Revision history for this message
Marc Summers (2aircraft) said :
#6

Oh, OK, I see what you mean.
And Yes, I forgot the wheel down.

But I need to wheel down a PAGE at a time
not just wheel(WHEEL_DOWN, 1)

So I will give that a try and see what happens.
It may take me some time to do this as I am
busy working on something else right now.

But I think wheeling down a page at a time
and not just one section of a page will fix
the problem.

Thanks for your help.