ELSE IF with RF 4.x : different way of use?


I have installed RF 4.1.3 and suddenly, my code with “ELSE IF” keyword are underlined, as if it was an error. But my test works. I suppose that with the update of RF (RF 3 to RF 4), the way of using this keyword are different but I don’t know (don’t understand also) why. I think that an argument is missing but I haven’t it. Could you help me ?

My configuration :

  • RF 4.13
  • Python 3.9.7
  • VS Code as IDE

My code :

he choose a type of real estate
[Arguments]    ${typeBien}
Click Element    ${rechercheAnnonceSelectBien}
    Run Keyword If    '${typeBien}'=='Appartement'    selection of APP type
     ...  ELSE IF    '${typeBien}'=='Maison'    selection of MAI type
     ...  ELSE IF    '${typeBien}'=='Garage'    selection of GAR type
     ...  ELSE IF    '${typeBien}'=='Fonds de commerce'    selection of FONDS COMM type
     ...  ELSE IF    '${typeBien}'=='Bien agricole'    selection of AGR type
     ...  ELSE IF    '${typeBien}'=='Immeuble'    selection of IMM type
     ...  ELSE IF    '${typeBien}'=='Bien viticole'    selection of VIG type
     ...  ELSE IF    '${typeBien}'=='Local activités'    selection of LAC type
     ...  ELSE IF    '${typeBien}'=='Local divers'    selection of DIV type

Thanks a lot !

If the syntax is underlined but the test works it means that this is a matter of the plugin you are using to recognize de RF code and not with RF itself

You can view which VSCode plugin is reporting this error by hovering over the underlined keyword or clicking the problems button on the status bar of the editor.


The extensions I used on VS Code are :

  • Robocorp Code
  • Robot Framework Language Server

It’s surprising because I haven’t the problem when I was on the office’s organisation.
Today, I’m working at home and I have this error…

I have only this kind of error for example :

Unexpected argument: '${typeBien}'=='Maison'

Looks similar to this issue


I finally found the solution.
In the RF docs, it’s written " NOTE: Robot Framework 4.0 introduced built-in IF/ELSE support and using that is generally recommended over using this keyword."

So I have re-write my keyword as :

IF '${typeBien}'=='Appartement'
   selection of APP type

And all works and syntax is not underlined anymore :slight_smile:

Conclusion : The “Run keyword if” is not recommended with RF 4 (but works)