hi
I am new at robot framework
I want fetch value from UI and after that performed the addition operation on that two value
result i get that two value like [‘703\nDC’] + [‘4773\nMC’]
fetch value like 703\nDC
second one 4773\nMC
@{element} = Get Items List ${loc_mc_dc}
@{CountList} = Create List
@{CountList1} = Create List
Append To List ${CountList} ${element}[0]
Append To List ${CountList1} ${element}[1]
${num1}= Set Variable ${CountList}
${num2}= Set Variable ${CountList1}
${mysum}= Set Variable ${CountList} + ${CountList1}
Log To Console ${mysum}
*** Test Cases ***
Sum Two Numbers
${num1}= Set Variable 703\nDC
${num1}= Convert To Integer ${num1.split()[0]}
${num2}= Set Variable 4773\nMC
${num2}= Convert To Integer ${num2.split()[0]}
${mysum}= Set Variable ${num1} + ${num2}
Log To Console This is not the expected result: ${mysum}
${mysum}= Set Variable ${${num1}+${num2}}
Log To Console This is a possible way to get the expected result: ${mysum}
${mysum}= Evaluate ${num1} + ${num2}
Log To Console This is another possible way to get the expected result: ${mysum}\nMy preferred way :).
Thanks
${num1}= Set Variable 703\nDC
${num1}= Convert To Integer ${num1.split()[0]}
${num2}= Set Variable 4773\nMC
${num2}= Convert To Integer ${num2.split()[0]}
${mysum}= Set Variable ${num1} + ${num2}
${mysum}= Set Variable ${${num1}+${num2}}
Log To Console This is a possible way to get the expected result: ${mysum}
after that i get result like that
Resolving variable ‘${[‘703’]+[‘4773’]}’ failed: Variable ‘${[}’ not found.
and after used ${mysum} = Set Variable ${num1}+${num2}
result is .[‘703’]+[‘4773’] only number
I also try with these one
${mysum} = Evaluate ${num1} + ${num2}
result is .[‘703’, ‘4773’]
My example was a fully working example. You need to adjust yours, to use the elements correctly.
When you see ${[‘703’]+[‘4773’]}, this means you did not get the first elements of the lists, before converting to integer. If you have a list mylist=[‘703’] you need to get its first element, for example: ${mynum}= Convert To Integer ${mylist[0]}.