if find or if exists SyntaxError

Asked by charliedaps on 2018-11-30

Hello everyone,

I can not find the solution for image search with an IF

The goal is that the action continues if the image is found and the action closes the window if the image is not found.

So I have

if find (image):
type(Key.F4, KEY_CTRL)

And here is the error indicated by sikulixide

SuntaxError ("mismatched imput "rightclick expecting indent",)
Error on the line rightclick(image)

I try with if exists(image): (same error)

Thank you in advance for your help.

Have a good day

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Last query:
Last reply:
masuo (masuo-ohara) said : #1

indentation means that a space at the beginning of a line of writing.

[error example]
if find (image):

[correct example]
if find (image):

masuo (masuo-ohara) said : #2

It is not a problem of SikuliX.
You have to learn Python's grammar.

charliedaps (charliedaps) said : #3

Thanks a lot for your answer.

Yes, I do not have an error message anymore but the "else" does not work.

I watched a little tutorial on the python language and I do not see where my mistake is.

Thank you for your help.


if find("1543482223289.png"):
    type(Key.F4, KEY_CTRL)
    type("v", KeyModifier.CTRL)
    type(Key.F4, KEY_CTRL)

masuo (masuo-ohara) said : #4

"does not work" mean FinFailed error?

read docs

use exists() instead of find()

charliedaps (charliedaps) said : #6

Thanks masuo.

Exists forks fine. I understend now the difference between exists and find ;)

Another question about the loop.

I would like this code to be executed 3 times and then the rest of the script continues.

I found some examples with print but I do not understand how to apply it to my code.

thank you in advance

masuo (masuo-ohara) said : #7

It is not a problem of SikuliX.
Now you have understood SikuliX.
Next you have to learn Python's grammar.

Manfred Hampl (m-hampl) said : #8

Manfred Hampl suggests this article as an answer to your question:
FAQ #1437: “[HowTo] repeat something in a Sikuli script (make loops)”.

Can you help with this problem?

Provide an answer of your own, or ask charliedaps for more information if necessary.

To post a message you must log in.