← Back to team overview

sikuli-driver team mailing list archive

[Question #248472]: Sikuli unable to find image on second iteration of loop

 

New question #248472 on Sikuli:
https://answers.launchpad.net/sikuli/+question/248472

If I dynamically define a region, sikuli is unable to find one of the images in the region the second time I run through the loop (it worked w/o issue the first time).  However, if I statically define the region, sikuli is able to find the image both times through the loop. 

I am curious as to why this is happening.  The report I am automating looks identical both times and all fields load at the same time, so the field is there when sikuli is looking for it.  That being said, I did try to add some wait statements in there, but it still did not work.  The only thing that worked was creating the region statically.

A sample of my code, with some additional comments, is below.



#lists for names
first = ["Harry", "Albus"]
middle = ["James", "Percival Wulfric Brian"]
last = ["Potter", "Dumbledore"]

#loops through creating and completing report
n = 0
for item in first:    
    click ("createReport.png")
    wait(.5)
    
    #defines the create report list as a region
    CreateReportR = find("createReport.png")
    CreateReportR.setW(700)
    CreateReportR = CreateReportR.below(300)
    
    #searches for report in the create report list
    s = 0
    while not CreateReportR.exists ("reportName.png"):
        CreateReportR.click (Pattern("downArrow.png").targetOffset(1,-15))  #scrolls through the list
        s += 1
        if s == 7:
            break
        
    else:
        CreateReportR.click ("reportName.png")  #selects report from the list
    
    
    #waits for the report to load
    wait ("title.png", 10)
    
    #completes the report
    click (Pattern("first.png").targetOffset(0,34))
    type (first[n])
    click (Pattern("middle.png").targetOffset(0,36))
    type (middle[n])
    click (Pattern("last.png").targetOffset(0,35))
    type (last[n])
    
    #increments n
    n += 1
    
    #defines the Bottom Line Assessment section as a region  #when i define the region using this commented method
    #BottomLineR = find("bottomLine.png")                                   #sikuli is unable to find the image the second time through
    #BottomLineR.setW(1600)
    #BottomLineR = BottomLineR.below(200)
    
    BottomLineR = (Region(215,674,1587,252))   #when using this method, it works both times

    
    #completes the Bottom Line Assessment section
    BottomLineR.click(Pattern("field1.png").targetOffset(53,0))
    BottomLineR.click("value1.png")
    wait(1)
    BottomLineR.click(Pattern("field2.png").targetOffset(59,0))  #sikuli is unable to find this field the second time
    BottomLineR.click("value2.png")
    BottomLineR.click(Pattern("field3.png").targetOffset(50,3))
    type("This is the assessment for report number %s." %n)
    BottomLineR.click("field3.png")  #clicks outside of the text box
    BottomLineR.click(Pattern("field4.png").similar(0.76).targetOffset(54,0))
    type("This report was created using Sikuli.")

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.