Thursday, June 23, 2022

Sikulix Study

I'm learning coding on the subject of RPA with Ubuntu on my dynabook N40 (lol). sikulix's typical functions find() and wait() match if an image is on the screen, but after getting used to them a bit, I want to do more advanced things(lol) , like "except:".

#
def log_print(m): # print debug code.
    print(m) # print a message. 
#
print(App.openLink("https://google.com")) # open google.com in standard browser
try:
    wait("image.png",15) # wait 15 seconds at the longest until image.png is found
    log_print("Found.")
except: # if not found for 15 seconds, come back here
    log_print("Not found.")
#
click() # without argument, left-click on the last match.

With find() and exists(), the image has to be on the screen at the time of execution, but with wait(), it waits until the image is displayed, and if it is, it proceeds without waiting. If you run the above code with the debug (-v) option, you will get

java -jar sikulixide-2.0.5.jar -r . -v
:
[debug] Region: wait: image.png appeared ....... [8180 msec])
:

You can see that it waits about 8 seconds, including the startup time of the browser. You can set the maximum wait time as long as you want, but since unexpected things often happen (:-o), if it is too long, you will be left waiting when debugging (:-).
You can write separate processes for when the image matches and when it does not match, like this.

Labels: , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home