Need help with Nested for loop

Hi Team,

Is there any way we can use nested for loop in robot framework

FOR ${config_element} IN @{CONFIG CARD OBJECTS}
Go To Config Group ${config_element}
${left_nav_obj} Get Left Nav Objects
FOR ${left_nav} IN @{left_nav_obj}
Add to dashboard ${left_nav}
END
END

I am not finding any other way to to execute this test case without inner for loop

Hi Madhurya,

I’ve not had any issue with nested for loops in robot framework, so yes you can.

FYI - use 3 back ticks (`) before and after to denote a code block so your formatting doesn’t get messed up.

Remember robot framework, like python indents need to remain consistent.

So your code should look something like this:

    FOR    ${config_element}    IN    @{CONFIG CARD OBJECTS}
        Go To Config Group    ${config_element}
        ${left_nav_obj}    Get Left Nav Objects
        FOR    ${left_nav}    IN    @{left_nav_obj}
            Add to dashboard    ${left_nav}
        END
    END

You also might need to try making some adjustments:

  • ${left_nav_obj} might need to be specifies as a list being returned from Get Left Nav Objects to ensure it actually is a list so that the inner for look can iterate it
  • ${left_nav_obj} might need an = to explicitly declare it’s a variable assignment
  • you may also want to log the result of ${left_nav_obj} to ensure you are getting what you expected in that variable

I would suggest trying it like this:

    FOR    ${config_element}    IN    @{CONFIG CARD OBJECTS}
        Go To Config Group    ${config_element}
        @{left_nav_obj} =    Get Left Nav Objects
        Log        ${left_nav_obj}
        FOR    ${left_nav}    IN    @{left_nav_obj}
            Add to dashboard    ${left_nav}
        END
    END

Hope that helps,

Dave.

Hi @damies13

I tried the same dave, but still it’s not working. It is not inside the loop

Hi Madhurya,

Can you show the actual robot script?

Yes the inner for loop appears to be running and passing it looks like it failing because the variable ${left_nav} is not set to any value?

I see where you set ${left_nav_obj}, but not where you set ${left_nav}.

So the reason for this failing looks like it has nothing to do with your original question.

Dave.

1 Like