While not exists Loop Throwing Error When I Have Else Condition at the End

Asked by Jennifer Coleman

I want to do a while loops that says while you don't see an error message, run this workflow. Else, if you do see the error message, take a screen shot of the entire screen.

When I add the else code in, the IDE throws a weird exception or error.

Here's the code in my script:

while not exists("ErrorScreenshot.png"):
           click(a)
           rightClick(a)
           #doubleClick(b)
           click(b)
           doubleClick(Pattern("1374609778702.png").similar(0.57))
           type(username)
           type(pwd)
           click("1374609885172.png")
           wait("1374609994953.png", 70)

           click("1374610198940.png")
           click("1374699689215.png")
           print username, pwd

      else:
           screen = Screen()
           file = screen.capture(screen.getBounds())
           print("Saved screen as "+file)

Here's the error message i get when I uncomment the else conditon:

[error] script [ *ModifyCredReadFromConfig ]] stopped with error at line --unknown--
[error] Could not evaluate error source nor reason. Analyze StackTrace!
[error] IndentationError: ('unindent does not match any outer indentation level', ('C:\\Users\\Sikuli\\AppData\\Local\\Temp\\sikuli-6590832730376844871.py', 40, 6, ' else:\n'))

Any ideas what is wrong? Is an else condition not allowed with while not exists?

Question information

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

the error clearly says:
IndentationError: ('unindent does not match any outer indentation level',

this means, that the else is not at the same indent level as the while.

see faq 1800

Revision history for this message
Jennifer Coleman (colej) said :
#2

Thanks RaiMan, that solved my question.