if not find Error

Asked by Dan

I'm trying to use switchApp to switch to the application if it's open, and if it's not open launch the program. The code executes a switchApp, then looks for an image, and if it doesn't find the image it should launch the program. This is similar to Question 99696: https://answers.launchpad.net/sikuli/+question/99696.

Here's my code:

switchApp("Internet Explorer")
sleep (2)
if not find( ):
   popup("Internet Explorer not found, will launch.")
   switchApp("C:\Program Files\Internet Explorer\IEXPLORE.EXE")

Here's the error:

[sikuli] [Error] source lineNo: 5
[sikuli] [Error] Traceback (innermost last):
  File "C:\DOCUME~1\dhannig\LOCALS~1\Temp\sikuli-tmp8089997933077535223.py", line 5, in ?
  File "C:\Program Files\Sikuli\sikuli-ide-full.jar\Lib/python/edu/mit/csail/uid/Sikuli.py", line 361, in find
 at edu.mit.csail.uid.SikuliScript.wait(SikuliScript.java:203)

 at edu.mit.csail.uid.SikuliScript.find(SikuliScript.java:178)

 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

 at java.lang.reflect.Method.invoke(Unknown Source)

edu.mit.csail.uid.FindFailed: edu.mit.csail.uid.FindFailed: Failed on waiting 1266870975704.png

Anyone know what the problem is? Any help will be appreciated. Thanks.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Dan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

your find() seems to raise an exception, instead of coming back with None (so your code would have worked).

place
setThrowException(False)
before your code. this tells the find()'s to not throw exceptions.

I learned, that with 0.9.8 the default for this flag is False - yours seems to be true ???

Are you sure, you are running the latest version?

Revision history for this message
Dan (dhannig) said :
#2

Hi Raiman, this worked! Thanks!

I'm not sure why my default is True...I was using 0.9.7 but will upgrade to 0.9.8 to see if the default changes or my installation was corrupted. Thanks again.

Revision history for this message
Andrey K (andrey5000) said :
#3

Need: to find the image which appears for some time and will disappear. People Andrey - login in chat and logoff, need clicked on nick.
Question: How to make search of such image? While not find (img) - doesn't work, because quits the program if doesn't find the image.

def clickAllPeople ( ) :
 while find( <imd>): # While open program games
   popup( "open cycle programm")
   peopleAndrey= find( )
   if peopleAndrey:
    click( )
    click( )
    type(Key.Enter)
   else: # THIS IGNORED CYCLE :(
     wait(1)
    popup( "end cycle programm")

switchApp("clickAllPeople.app")
sleep(2)
popup("start")
clickAllPeople ( ) # 18Line - this error Type 2
popup("end")

How this worked:
opup windows:
a) Start
b) open cycle programm
c) Error on line 18

Problems:
1. Ignred cycle , if not find image!!!!!
2. Exit from program on 18 line :(
Error Type 2:
Traceback (most recent call last):
  File "C:\Windows\TEMP\sikuli-tmp5331074520204094578.py", line 18, in <module>
    clickAllPeople ( )
  File "C:\Windows\TEMP\sikuli-tmp5331074520204094578.py", line 4, in clickAllPeople
    peopleAndrey= find("1285448957124.png")
  File "D:\Program Files\Sikuli\sikuli-script.jar\Lib\sikuli\Region.py", line 59, in find
  Line 2, in file C:\Windows\TEMP\sikuli-tmp5331074520204094578.py

 at edu.mit.csail.uid.Region.wait(Region.java:240)

 at org.python.proxies.sikuli.Region$Region$1.super__wait(Unknown Source)

 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

 at java.lang.reflect.Method.invoke(Unknown Source)

edu.mit.csail.uid.FindFailed: FindFailed: 1285448957124.png can't be found.
  Line 2, in file C:\Windows\TEMP\sikuli-tmp5331074520204094578.py

Revision history for this message
Andrey K (andrey5000) said :
#4

Add: The reason of an output from the program - this line because the image isn't found

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

Use exists() instead of find.

why? look: https://answers.launchpad.net/sikuli/+question/123366