# How to save multiple output values received from For Loop of one script to variables.robot

**URL:** <https://forum.robotframework.org/t/how-to-save-multiple-output-values-received-from-for-loop-of-one-script-to-variables-robot/6709>\
**Category:** Robot Framework\
**Created:** [23 January 2024 16:43 UTC](https://forum.robotframework.org/t/how-to-save-multiple-output-values-received-from-for-loop-of-one-script-to-variables-robot/6709 "2024-01-23T16:43:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![adskul](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@adskul](https://forum.robotframework.org/u/adskul)\
**Post date:** [23 January 2024 16:43 UTC](https://forum.robotframework.org/t/how-to-save-multiple-output-values-received-from-for-loop-of-one-script-to-variables-robot/6709/1 "2024-01-23T16:43:05Z")

</div>

Hi, I am using Robot Framework, Selenium in Pycharm. I want;

1. To save multiple return values in different variables.
2. These variables I need in variabls.robot.
3. After that I want to fetch these values one by one from variables.robot in the for loop of different scripts.

Below is the requirement example.

I have below web table which I access in my first script.

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/1/1eca72b0361bc96f916b017c1107765ed7e8882a.png)

1. I want to navigate through all the rows and get the values of Product ID one by one (In first script). Here I am using loop to get the values and processing it.
2. Then want to save all the Product IDs in different variables in variable.robot file
3. Finally want to call these product IDs in multiple other scripts. In few scripts I need one or two id’s and in couple of scripts I need them to bring one by one in loop.

I was thinking about list but not able to acheive it.

- Please suggest if any solution is with list too.
- Want to know how to save multiple outputs received from For Loop to different variables.
- also want to know how to save these values from first script to variables.robot so it will be easy call these values any other scripts.

I am getting list in one script but how to send it to variables.robot or call these values one by one in other scripts?

```
@{list} Create List
    Append To List ${list} ${ProductID}

```

---

<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:** [23 January 2024 18:55 UTC](https://forum.robotframework.org/t/how-to-save-multiple-output-values-received-from-for-loop-of-one-script-to-variables-robot/6709/2 "2024-01-23T18:55:57Z")

</div>

You can save to a CSV file and then read them.  
Or you can save as variable file (.yml, .json, .py) and they import. In this case you need to have more complex data structures.

---

<div class="post-metadata">

**Author:** ![adskul](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@adskul](https://forum.robotframework.org/u/adskul)\
**Post date:** [24 January 2024 16:46 UTC](https://forum.robotframework.org/t/how-to-save-multiple-output-values-received-from-for-loop-of-one-script-to-variables-robot/6709/3 "2024-01-24T16:46:27Z")

</div>

I am using below code to create the list

```
${list}= Create List ${ProductID}
    ${data}= create list ${list}
    Append To Csv File ProductID.csv ${data}

```

I am gettng below CSV

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/1/1c33f7bf654779761694e47ada214ef9426ce50c.png)

Then calling saved values in another script like

```
${rows} = get element count xpath=//*[@id="YearlyReport"]/tbody/tr
    sleep 2
    log to console Total Rows ${rows}

  ${ProductID}= Read Csv File To List ProductID.csv
  FOR ${element} IN @{ProductID}
        Log To Console ${element}[0]

   FOR ${rowno} IN RANGE 1 ${rows}+1

    Input Text xpath=//input[@placeholder='Search ...'] ${element}[0]
    sleep 5

    ${Details} = Get Text xpath=//*[@id="YearlyReport"]/tbody/tr[${rowno}]/td[10]
    log to console In Search details of ${element}[0] is ${Details}

```

I am getting below error

**List ‘${element}’ has no item in index 0**. If I change value to 1 then it gives same error **List ‘${element}’ has no item in index 1.**

Any suggestions ?

---

<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:** [25 January 2024 00:43 UTC](https://forum.robotframework.org/t/how-to-save-multiple-output-values-received-from-for-loop-of-one-script-to-variables-robot/6709/4 "2024-01-25T00:43:47Z")

</div>

Here is an example of dealing with CSV lists:

```python
Language: English

***Settings***
Library CSVLibrary
Library OperatingSystem AS OS

***Test Cases***
Save data
    [Setup] Create File ${CURDIR}${/}ProductID.csv
    ${ProductID}= Create List A1 B1 C1 D1 E1
    Append To Csv File ${CURDIR}${/}ProductID.csv ${ProductID}

Read data
    ${ProductID}= Read Csv File To List ${CURDIR}${/}ProductID.csv
    Log Many ${ProductID}
    # We get [['A1', 'B1', 'C1', 'D1', 'E1']]
    # So, we must select element 0 of this list
    ${products}= Set Variable ${ProductID[0]}
    FOR ${element} IN @{products}
        Log ${element}
    END
    [Teardown] OS.Remove File ${CURDIR}${/}ProductID.csv

```

---

<div class="post-metadata">

**Author:** ![adskul](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@adskul](https://forum.robotframework.org/u/adskul)\
**Post date:** [25 January 2024 16:36 UTC](https://forum.robotframework.org/t/how-to-save-multiple-output-values-received-from-for-loop-of-one-script-to-variables-robot/6709/5 "2024-01-25T16:36:39Z")

</div>

Thanks ! It is working.

```
${products}= Set Variable ${ProductID[0]}
FOR ${element} IN @{products}
Log ${element}

```
