sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #00947
Re: [Question #143114]: goto or continue execution from other line
Question #143114 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/143114
Status: Open => Answered
RaiMan proposed the following answer:
--- 1. if: elif: elif: elif: ... else:
In other languages this would be a case or switch construct: testing some alternatives one after the other and executing the first block whose condition is met. if none mets, the else block is executed. Each elif: needs a condition expression to evaluate to True or False.
--- 2. your example above:
if not exists(something,3):
# statement block 1
else:
# statement block 2
!# statement block 3!
- if something does exist,block 1 will be skipped
- if something does not exist,block 1 will be processed
But after processing block 1, i want it to continue to block 3 in the "else" B'cause i need to reuse my code!
This means block3 has to processed in both cases?
here you have it
if not exists(something,3):
# statement block 1 executed if something does not exist
else:
# statement block 2 executed if something exists
# statement block 3 always executed
I do not know your programming skills and especially the knowledge of
Python: it is always a good idea to first have some workflow designed
and written down representing, what you want to achieve. In Sikuli this
often is some translation of your click and key-press behavior to
achieve the same manually.
I usually write this down directly in Python using comments and print
statements.
-- typical situation with a browser automation:
# open browser and wait for it to be ready
openApp("C:\\Program Files (x86)\\Opera 11.00 alpha\\opera.exe")
# wait for it to be ready or find out, wether we switched to a running instance
wait(3) # TODO to be replaced with more intelligent code later
# open a webpage
# - switch to address field (Firefox ctrl-l)
type("l", KEY_CTRL)
# - fill in url and press enter
url = "this-is-the-url"
paste(url); type(Key.ENTER)
# wait for webpage to be ready
if not exists(something, 10):
print url, "not there after 10 seconds"; exit(1)
# TODO later on we will try to take some corrective actions in this case
# we have to do a login
# TODO to be programmed later
popup("Please login and press ok when ready")
# wait for login to be processed
if not exists(something1, 10):
print url, "login might have failed - waiting 10 seconds"; exit(1)
# TODO later on we will try to take some corrective actions in this case
# we start clicking now
click(start)
# do we have to wait?
wait(0) # TODO to be adjusted?
# evaluate result
if exists(something2, 0):
print "we have situation something2"
# we have to click some options
click(option1)
click(option5)
# TODO: we have to check wether option4 is on and switch it off
elif exists(something3, 0)
print "we have situation something3"
# TODO: actions later
exit() # in this state of development we have to stop here
else:
print "neither situation something2 nor something 3"
exit(1)
# TODO should not happen, we have to evaluate
happy scripting ;-)
BTW: If you have to repeat something, FAQ 1437 might help
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.