scroll down a page with findAll list

Asked by Marc Summers on 2019-01-07

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:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Marc Summers
Solved:
2019-01-08
Last query:
2019-01-08
Last reply:
2019-01-08
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

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 ?

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

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)

Manfred Hampl (m-hampl) said : #5

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

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.