IF statement in robot framework

Hi everyone, i’m new working with robot framework and i’ve been having trouble with the IF statement.
I’m trying to do this:
image

But i got this error: ‘If’ is a reserved keyword.

What am i doing wrong?

Hi, @maurosouto27! Are you using Robocorp tools? What is the rpaframework version in your conda.yaml? Try with rpaframework==9.6.0 (that includes Robot Framework 4 with the native IF support).

Hi, im not using Robocorp tools, im already using rpaframework==9.6.0

Can you share the full keyword/task where you call that IF / ELSE?


i had to change it a bit

i need to use nasted IF but i dont know if the syntax is correct

At least nesting IF, ELSE IF, and ELSE seems to work even with many levels of nesting. Maybe try using IF instead of Run Keyword If and see if it makes any difference?

@maurosouto27

I would restructure your IF branching to make cleaner. And there is no need to use Run Keyword If when you are using IF, ELSE IF, and ELSE

so something like this

*** Keywords ***
Handle Ages 18-40
    Log    correct steps here

Handle Ages 41-50
    Log    correct steps here

Handle Ages 51-60
    Log    correct steps here

Handle Ages 61-65
    Log    correct steps here

Handle Other Age Groups
    Log    correct steps here

*** Tasks ***
Minimal task
    IF    ${row}[EDAD]==18-40
      Handle Ages 18-40
    ELSE IF    ${row}[EDAD]==41-50
      Handle Ages 41-50
    ELSE IF    ${row}[EDAD]==51-60
      Handle Ages 51-60
    ELSE IF    ${row}[EDAD]==61-65
      Handle Ages 61-65
    ELSE
       Handle Other Age Groups
    END

@jani @mika
As i said in the first post when i use only “IF” i got the error: “‘If’ is a reserved keyword.”

Now i changed it again, i would like it to be like this:

but im still getting that error

what did you mean by this ? how you are running your task ?

@maurosouto27 could you double check that you have indented also the top level IF statements? The syntax is such that keyword name (or task name) is not indented, but after that all code lines of that keyword must be indented with 2+ spaces.


*** Keywords ***
My Keyword
    IF  condition
      do something
    END

My next keyword
    do something else