how do i break this code and start over if image isn't there

Asked by MJ

hanf = exists("1484622139127.png")
while hanf:
# x = 9
# print x
# wait(10)
    import os
    click(Pattern("1484693748414.png").targetOffset(0,15))
    wait(5)
    os.system("C:\\sikuli\\msaccess_macro_dm_send.bat")
    type(Key.PAUSE)
    idsList = [] # empty list/array
    dir = "c:/sikuli/" # the folder, where your ids.txt is
    idsFile = os.path.join(dir, "whom.txt") # makes a Windows filename
    idsFile2 = os.path.join(dir, "message.txt") # makes a Windows filename

    f = open(idsFile) # opens ids file
    for line in f.readlines(): # reads line by line
        id = line.strip() # get rid of newline
        print id
        idsList.append(id) # add id to list/array
    f.close() # close file

    g = open(idsFile2) # opens ids file
    for line in g.readlines(): # reads line by line
        id2 = line.strip() # get rid of newline
        print id2
        idsList.append(id2) # add id to list/array
    g.close() # close file
    #wait(20)
    #click("1484622115843.png")
    wait(5)
    click("1484622139127.png")
    wait(5)
    click("1484622329031.png")
    wait(10)
    click("1484622402013.png")
    wait(10)
    click(Pattern("1484622684822.png").targetOffset(-19,0))
    type(id)
    wait(20)
    click(Pattern("1484623124359.png").targetOffset(-4,71))
    #wait(1)
    #click(Pattern("1484623124359.png").targetOffset(-4,71))
    wait(10)

----------- This is the line that either continues if matches or starts back at the top
    click(Pattern("1484623171819.png").targetOffset(-13,1))
-----------

    wait(5)
    type(id2)
    wait(5)
    click("1484623592665.png")
    wait(5)
    click(Pattern("1484690912192.png").targetOffset(-98,0))
    wait(5)
    click(Pattern("1484690912192-1.png").targetOffset(-98,0))
    wait(300)

Thanks

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
MJ
Solved:
Last query:
Last reply:
Revision history for this message
Vadivelan (velan) said :
#1

while exists("1484622139127.png"):
    .....
    .....
    if exists(Pattern("1484623171819.png").targetOffset(-13,1)):
        click()
    else:
        continue

Revision history for this message
MJ (mjpmgr) said :
#2

Perfect I guess it was a stupid question..

A Many Thanks