简体   繁体   中英

Sikuli scripting

I want to write a sikuli script which can clear the "Recycle bin" if it is full (when executed first time) and need to check the icon if it is empty and display (Recycle bin is empty)

Following is the code which I tried:

Try 1 - while not exists("RecycleBin-1.png"): --> Image when the "Recycle bin is full" rightClick("RecycleBin-1.png") --> "Right clicking the Recycle bin" full icon. click("EmptyRecycle.png") --> Image of confirmation to delete all items.

click("1406033619416.png") --> Image of "Recycle bin" is empty
print ("Recycle bin has been emptied")
else:
while exists ("RecycleBin.png"): 
print ("Recycle bin is already empty")

Try 2 - while not exists("RecycleBin-1.png"): rightClick("RecycleBin-1.png") click("EmptyRecycle.png")

click("1406033619416.png")
print ("Recycle bin has been emptied")
else:
print ("Recycle bin is empty")

My problem is either the while loop before else gets executed (or) the else part is executed in sikuli inspite of the Recycle bin is empty (or) full, sikuli is not doing any complete analysis and executing it as necessary.

Please anybody help me out on this as I am relatively new to sikuli and python.

Thanks, V.Prashanth

As a first resort, go to where the picture of the icon appears in your code in the Sikuli IDE. Try clicking on the picture, then go to the matching preview tab, and change the similarity from the default of .7 to something much higher (.9 or .95), and see if that resolves the issue.

Because the picture of the full recycle bin and the empty recycle bin are very similar, upping the similarity forces Sikuli to only allow a match when it is almost identical (90% or 95% match) to the picture you've captured in the IDE, rather than returning a match on anything that is only a 70% match.

If that doesn't fix the issue, there may be other things to try, but I would try that first.

autoKarma is spot on, you need to increase the similarity; since the trash icon is static I'd push it all the way to 99%. FYI, The IDE suppresses the text ".similar(0.##)" below, but if you check the .py file that the IDE generates on save it'll be there.

I revised your loops a bit more, my experience with Sikuli is that you end up with many...many loops to ensure Sikuli can handle the oddities that inevitably come into play with pattern-recognition. The code below is untested code and loosely reflects a Mac, although at least mine pops up a "are you sure you want to delete this" warning before it begins clearing, so your milage may vary.

def take_out_the_trash():
    while exists(Pattern("Full_RecycleBin.png").similar(0.99)):
        rightClick("Full_RecycleBin.png")
        wait 1
        while exists(Pattern("EmptyRecycle_Button.png").similar(0.99)):
            click("EmptyRecycle_Button.png")
            wait 1
        while exists (Pattern("Emptying_trash_in_progress.png").similar(0.90)):
             wait 2

take_out_the_trash()

For the "Emptying_trash_in_progress" picture, be careful not to get the progress bar in the picture; just find some static text/menu that'll be safe to reference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM