While loop that stops when the condition is no longer met

Asked by Mirak

I would like first of all to thank you all for the contribution you make to this site, I learn from you all.

I set up an automation script that scrolls down to the bottom of the web page, clicks on a button and repeat the process but I'd like it to break when the button ("SHOWMORECOMM-1.png") is no longer visible. Here is what I have so far:

switchApp("Firefox.app")

while not exists("SHOWMORECOMM-1.png") and not exists("1522075524740.png"):
    wait(5)
    type(Key.END)

    wait("SHOWMORECOMM-1.png", 2)
    click("SHOWMORECOMM-1.png")
    wait(5)

    if exists("SHOWMORECOMM-1.png") and exists("1522075524740.png"):
        click("SHOWMORECOMM-1.png")
    else:
        break

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

while not exists("SHOWMORECOMM-1.png") and not exists("1522075524740.png"):
    wait(5)
    type(Key.END)

    if exists("SHOWMORECOMM-1.png", 2):
        click()
    wait(5)

    if exists("SHOWMORECOMM-1.png") and exists("1522075524740.png"):
        click("SHOWMORECOMM-1.png")
    else:
        break

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

My way:

#####
switchApp("Firefox.app")

type(Key.END) # go to end for the first time

while exists("PageEndBtn.png",2): # check for element for 2 seconds
    click() # click on last found location form above
    wait(5) # page reload
    type(Key.END) # go to the end of page

#####
You may decide to replace wait above with waiting for some elements and adjust times as needed

Revision history for this message
Mirak (ubuntu-spirit) said :
#3

Thanks RaiMan, that solved my question.