I have the following code that always returns a findfailed error when it doesn't find the end_turn
image.
def clickCards():
# region.wait(end_turn,90)
# search for the cards and click all of them
if exists(zero):
z = region.findAll(zero)
for i in z:
click(i)
sleep(1)
else:
pass
if exists(one):
o = region.findAll(one)
for i in o:
click(i)
sleep(1)
else:
pass
click(end_turn)
while exists(level):
with region:
if exists(end_turn):
clickCards()
elif exists(victory):
click(victory)
else:
wait(end_turn,90)
I am trying to automate the following game visual:
- Card Games starts
- click cards while end button is available
- end turn with end turn button
- keep playing until I win
- Victory appears and no end turn button is visible anymore
- click the victory image
The script will run, but when I win it will go into an error that it couldn't find the end_turn
button.
Error Message:
[error] script [ axieTest ] stopped with error at line --unknown--
[error] Error caused by: Traceback (most recent call last): File "C:\Users\Mortada\Desktop\axieTest.sikuli\axieTest.py", line 47, in <module> wait(end_turn,90) File "C:\Users\Mortada\AppData\Roaming\Sikulix\Lib\sikuli\Sikuli.py", line 69, in wait return SCREEN.wait(target, timeout) Line 2761, in file Region.java
at org.sikuli.script.Region.wait(Region.java:2761)
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)
org.sikuli.script.FindFailed: FindFailed: end_turn.png: (129x48) seen at (1439, 676) with 1.00 in R[322,156 1278x763]@S(0) E:Y, T:3.0 Line 2761, in file Region.java
I had a similar issue. Luckily the docs are good in this case. https://sikulix-2014.readthedocs.io/en/latest/region.html#exceptionfindfailed
Its by design that
region.findAll()
will raise aFindFailed
exception when it cannot find a match (implicit or explicit). In your case, I think its the implicit call during theclick()
operation.Fortunately, Sikuli gives a way out by letting one toggle this exception.
You can use setThrowException() to toggle this exception for a region.