Loop break by if exists ("path to image") not work :(

Asked by Adrian Zieliński on 2018-09-19

Hi all!

I have sth like below:

for n in range(10):
        type (Key.F6, KeyModifier.SHIFT)
        wait(2)
        for n in range(4):
            type(Key.TAB)
        type(Key.ENTER)
        x=0
        y=+16
        mouseMove(x,y)
        mouseDown(Button.LEFT)
        mouseUp(Button.LEFT)
        wait(1)
    if exists(Region(86,355,431,144)):
        find("1537344880118.png").click()
        break;

Without "if exists" it works perfect. But problem is that i not always have the same number of area which should be marked. So I want stop loop when message about missing area will show inside program.

I have such warn statement:

[error] script [ LOOP01 ] stopped with error at line --unknown--
[error] Error caused by: IndentationError: ('unindent does not match any outer indentation level', ('C:\\Users\\ZIELIN~1\\AppData\\Local\\Temp\\Sikulix_487760013\\sikuli-4482208172387115684.py', 15, 4, ' if exists(Region(86,355,431,144)):\n'))

Any advice?

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Adrian Zieliński
Solved:
2018-09-21
Last query:
2018-09-21
Last reply:
2018-09-19

I also tried sth like below:

while True:
    if not exists("1537362590995.png",0):
        for n in range(10):
            type(Key.F6, KeyModifier.SHIFT)
            wait(2)
            for n in range(4):
                type(Key.TAB)
            type(Key.ENTER)
            x=0
            y=+16
            mouseMove(x,y)
            mouseDown(Button.LEFT)
            mouseUp(Button.LEFT)
            wait(1)
    else:
        wait(1)
        break

Now, no warn statements inside debug console was showed, loop works but no break when img ("1537362590995.png",0): will show.

Jitendra patel (jpatel1011) said : #2

there maybe a slight delay between the last action and the image showing
try if not exists("1537362590995.png"):
this will wait the default 3 seconds to see if the image appears

masuo (masuo-ohara) said : #3

If exists() returns True, there seem to be images similar to "1537362590995.png" on the screen.
Since the minimum similarity is 70% in default, change the minimum similarity to a value greater than 70%.
https://sikulix-2014.readthedocs.io/en/latest/pattern.html?#Pattern.similar

[example]
exists(Pattern("1537362590995.png").similar(0.90))

Hi,

you mean sth like this:

while True:
    if not exists("1537362590995.png"):
        for n in range(10):
             ............

?

I tried this but without results :(

Hi,

Probably I found solution :P I've just break loop in wrong moment :P

Here it is:
for n in range(20):
    type (Key.F6, KeyModifier.SHIFT)
    wait(2)
    if exists("1537372097090-1.png",2):
        find("1537372638707.png").click()
        break
    for n in range(4):
        type(Key.TAB)
    type(Key.ENTER)
    x=0
    y=+16
    mouseMove(x,y)
    mouseDown(Button.LEFT)
    mouseUp(Button.LEFT)
    wait(1)

Yup,

now everything works correct.

Thx for help!