Whats wrong with ELIF

Asked by Colby Black

(Excuse indentions from pasting, but what is wrong with the elif statement? Gives error..

[error] Stopped
[error] An error occurs at line 178
[error] Error message:
SyntaxError: ("no viable alternative at input ':'", ('/var/folders/-U/-UHGSbvJF+8HyAH3a2YZ+k+++TI/-Tmp-/sikuli-tmp1139829177390629941.py', 178, 12, ' elif:\n'))

--------------------------------------------------

if exists(excelEMAIL):
            rightClick(excelEMAIL)
            wait(3)
        else:
            popup("Please configure Excel Correctly")# this is because excel can't be scrolled to the right, with email section not showing
            wait(5)
        click(excelCOPY)
        if exists(tabGMAIL):
            click(tabGMAIL)
        elif:
            click(tabGMAILblue)
        else:
            click(tabSETTINGS)
            click(settingsCLEARbrowsing)
            wait(settingsCLEARbrowsingCLEAR,20)
            click(settingsCLEARbrowsingCLEAR)
            click(exitCHROME)
            ac= App("Google Chrome")
            ac.open()
            type(",",KEY_CMD)
            click(settingsEXTENSIONS)
            click(settingsPROXYoptions)
            click(tabEXTENSTIONS)
            click(settingsSETTINGS)
            click(settingsSHOWadvanced)
            click(settingsCLEARbrowsing)
            wait(settingsCLEARbrowsingCLEAR,10)
            click(settingsCLEARbrowsingCLEAR)
            type("t", KEY_CMD)
            type("www.facebook.com")
            type(Key.ENTER)
            type("t", KEY_CMD)
            type("www.gmail.com")
            type(Key.ENTER)
            if exists(setupSUCCESS):
                click(tabPOXY)
                exit()
            else:
                popup("Configur Browser")

Question information

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

google: Python elif

gives:
http://www.tutorialspoint.com/python/python_if_else.htm

which says:
The syntax of the if...elif statement is:
if expression1:
   statement(s)
elif expression2:
   statement(s)
elif expression3:
   statement(s)
else:
   statement(s)

which means, that elif needs a condition like if.
it is only a short form for:
if something:
    pass
else:
    if somethingelse:
        pass
    else:
        if somethingelsemore:
            pass
......

so it saves indentation.

Revision history for this message
Colby Black (coboblack) said :
#3

This is the section I'm concerned with. I give it an IF (If gmail tab exists, click) ,Else if, (the blue gmail tab is there, click that instead.) else ( If neither of those are true, click settings to start a new action) What is incorrect about that?

if exists(tabGMAIL):
            click(tabGMAIL)
elif:
      click(tabGMAILblue)
else:
      click(tabSETTINGS)
       click(settingsCLEARbrowsing)

Revision history for this message
Best j (j-the-k) said :
#4

Then you should write:

if exists(tabGMAIL):
            click(tabGMAIL)
elif exists(tabGMAILblue):
      click(tabGMAILblue)
else:
      click(tabSETTINGS)
      click(settingsCLEARbrowsing)

As RaiMan said, "elif" needs a statement to evaluate.

Revision history for this message
Colby Black (coboblack) said :
#5

Thanks j, that solved my question.

Revision history for this message
Colby Black (coboblack) said :
#6

Thanks so much, I thought I was giving it a statement, I didn't know it needed to be on same line. I get it know, thanks so much. And raiman. I implemented those shortcuts you showed me and it cut the time in half! You're awesome!

Revision history for this message
grovalmitch (grovalmitch) said :
#7