How to make script with sikuli that waits 1 button

Asked by Roy Henri Waldemar Järvinen

This is a continuation of last question. Thanks for last answer!

1. question: I have to make a script what waits for example "Ex" button and when it finds it, it will clicks "Rt" button, "Ec" button and then "Ty" button and after that I wil restart the script and waits Ex button again. There is a app what don't do that without me.

Here is my try:
ebTitle = "appname"
ebTitle = App(ebTitle)

if find(Ex button):
   ebApp.focus()
   click(Rt button), click(Ec button), click(Ty button)

Do it works?

2. question: Is there something way to stop sikuli script if it will goes haywire otherwise launch resource management and stop process?

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:

This question was reopened

Revision history for this message
RaiMan (raimund-hocke) said :
#1

To understand some of my comments you might have to look in the docs (http://sikuli.org/docx/)

--- Have a look at "How to Loop": FAQ 1437
to start something all over again in the same script

--- your if construct "converted" to Python

if find(Ex button):
   ebApp.focus()
   click(Rt button); click(Ec button); click(Ty button)

or even better (Python Programming Guideline)

if find(Ex button):
   ebApp.focus()
   click(Rt button)
   click(Ec button)
   click(Ty button)

--- using if find():
no good idea, since find will always end the script if not found

(if this is intended, then there is no need for an if ;-)
find(Ex button) # script stops if FindFailed
ebApp.focus() # only executed if find is successful
click(Rt button)
click(Ec button)
click(Ty button)

better use exists() in your case

if exists(Ex button):
   ebApp.focus()
   click(Rt button)
   click(Ec button)
   click(Ty button)

--- FindFailed
it is vital to understand http://sikuli.org/docx/region.html#exception-findfailed to write robust Sikuli scripts

e.g. if after click(Rt) it might be more than 3 seconds for Ec to get visible:
click(wait(Ec, 10)) # waits max 10 seconds for Ec to get visible

--- stop a script
use exit(x)
where x is returned to the environment (exit() eqivalent to exit(0))

Revision history for this message
Roy Henri Waldemar Järvinen (roy-jarvinen) said :
#2

Thanks!

Revision history for this message
Roy Henri Waldemar Järvinen (roy-jarvinen) said :
#3

Here is my plan:
-
ebTitle = "EpicBot"
ebApp = App(ebTitle)
if not App(ebTitle).window():
 exit()
while True:
 if not exists(Ex button):
  break
 else:
  pass
  ebApp.focus()
  click(Rt)
  click(Ex)
  click(Ty)
if exists(Py image):
 exit()
while True:
 range(3)

I try make a repeater which
1. At first, it will check that the app is open. If not, it exits
2. Waits Ex button and when it finds it will click those Rt, Ex and Ty
3. When 2. is done it will check Py image. If it see it, the script will stop
4. If Py image isn't visible, it jumps to 3. line and start it again

My problem is that it will exit on Py image check even if it isn't visible.
What is wrong with script setup?

Revision history for this message
RaiMan (raimund-hocke) said :
#4

Hope it helps

ebTitle = "EpicBot"
ebApp = App(ebTitle)
if not App(ebTitle).window():
 print "ebApp not running"
 exit(1)
ebApp.focus()
wait(1)
# now we have the frontmost ebApp window visible

# is Ex Button in that window???
# if not: what makes it come into existence?

# to make it clearer I use 3 blanks for one indentation level (tabs are not working here :-(

while True:
   if not exists(Ex button):
      wait(1)
      continue # we loop until Ex button exists
   # here we come when Ex Button is there
   click(Rt)
   click(Ex)
   click(Ty)
   # do you have to wait here longer than 3 seconds?
   if exists(Py image):
      break # we leave the loop
   # we loop again
# Py image was found
print "Py image" was found"
# the script terminates

Can you help with this problem?

Provide an answer of your own, or ask Roy Henri Waldemar Järvinen for more information if necessary.

To post a message you must log in.