Troubles with adressing elements of lists

Hi everyone. I’ve been running into the following error. Ive go this list with a couple of value pairs.
I need to adress the second value of each pair, but I cannot figure out how. Can somebody please help.

*** Settings ***
Library           Collections

*** Variables ***
@{mbas}           ['DEEL1-A', 'DEEL2-A']    ['DEEL1-B', 'DEEL2-B']
 
*** Test Cases ***
MBA uitzoeken
    FOR    ${mba}    IN    @{mbas}
        Log    ${mba}
        ${first_element}=    Set Variable    ${mba[0]}
    END

Your list variable is actually defined as a list of 2 string elements in the example you provided.

Here is a proper way to define a list of list, using inline python:
@{mbas} ${{['DEEL1-A', 'DEEL2-A']}} ${{['DEEL1-B', 'DEEL2-B']}}
It would also be possible to define the sublist in other variables, then use these variables to define the top list.

Otherwise, you have the proper syntax to get the first element of each item of the list ${mba[0]}.
The second element is available as ${mba[1]}.
Note that this other syntax works too: ${mba}[1]

Check it out on the online playground.

Also note a new VAR syntax is available in RF 7, to replace Set Variable. And that you can update your existing tests and keyword automatically using tidy ReplaceWithVAR transformer

1 Like