Reputation: 88
I want to get value of item a
The structure is like
${dict1} Create Dictionary a=1 b=2
${dict2} Create Dictionary x=1 y=2
${list1} Create List ${dict1} ${dict2}
${master_dict} Create Dictionary payload=${list1}
Now I know, I can use below logic to access items indirectly
${dict} Get From List &{master_dict}[payload] 0
${item} Set Variable &{dict}[a]
But I want to know, is there a direct way to access it. I have already tried
${item} Set Variable &{master_dict.payload[0]}[a]
and
${item} Set Variable @{master_dict.payload[0]}[a]
Upvotes: 2
Views: 66
Reputation: 385970
When using robot's extended variable syntax you have to remember that what you provide must be valid python. In your case that means that payload
needs to be "payload"
, and a
needs to be "a"
(or the single-quote equivalent).
If you were doing this in python code, it would look like this:
item = master_dict['payload'][0]['a']
Therefore, from within robot, everything inside the curly braces needs to look the same. For example:
${item}= set variable ${master_dict['payload'][0]['a']}
You can also treat the value as a dictionary and move the last part outside of the curly braces, in which case you only need quotes inside the curly brace.
${item}= set variable &{master_dict['payload'][0]}[a]
Upvotes: 2