# How to add two variables in robot framework

**URL:** https://forum.robotframework.org/t/how-to-add-two-variables-in-robot-framework/5065
**Category:** Robot Framework
**Created:** [13 December 2022 14:28 UTC](https://forum.robotframework.org/t/how-to-add-two-variables-in-robot-framework/5065 "2022-12-13T14:28:33Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![rahul12](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@rahul12](https://forum.robotframework.org/u/rahul12)
#### Post date: [13 December 2022 14:28 UTC](https://forum.robotframework.org/t/how-to-add-two-variables-in-robot-framework/5065/1 "2022-12-13T14:28:33Z")

</div>

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}

```

---

<div class="post-metadata">

### Author: ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)
#### Post date: [13 December 2022 18:01 UTC](https://forum.robotframework.org/t/how-to-add-two-variables-in-robot-framework/5065/2 "2022-12-13T18:01:08Z")

</div>

Here is my answer based on your example:

```python
***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 :).

```

---

<div class="post-metadata">

### Author: ![rahul12](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@rahul12](https://forum.robotframework.org/u/rahul12)
#### Post date: [14 December 2022 04:36 UTC](https://forum.robotframework.org/t/how-to-add-two-variables-in-robot-framework/5065/3 "2022-12-14T04:36:05Z")

</div>

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’]

---

<div class="post-metadata">

### Author: ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)
#### Post date: [14 December 2022 09:21 UTC](https://forum.robotframework.org/t/how-to-add-two-variables-in-robot-framework/5065/4 "2022-12-14T09:21:33Z")

</div>

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]}`.
