Read CSV File more than one time in a loop

I’m trying to do a looping infinity reading a CSV file. However, once the variable !csvReadStatus is equal to “end_of_file” and it is read-only a can’t start reading the file again. How can I do to read the file 2nd time, 3rd time and so on… in a looping infinity that only will stop when stop the macro on console.

{
“CreationDate”: “2018-5-25”,
“Commands”: [
{
“Command”: “store”,
“Target”: “120”,
“Value”: “!timeout_macro”
},
{
“Command”: “store”,
“Target”: “fast”,
“Value”: “!replayspeed”
},
{
“Command”: “label”,
“Target”: “start”,
“Value”: “”
},
{
“Command”: “store”,
“Target”: “1”,
“Value”: “!csvReadLineNumber”
},
{
“Command”: “store”,
“Target”: “OK”,
“Value”: “!csvReadStatus”
},
{
“Command”: “echo”,
“Target”: “— Read CSV Test starts here —”,
“Value”: “”
},
{
“Command”: “label”,
“Target”: “TESTSTART”,
“Value”: “”
},
{
“Command”: “csvRead”,
“Target”: “ReadCSVTestData.csv”,
“Value”: “”
},
{
“Command”: “echo”,
“Target”: “Status = ${!csvReadStatus}, line = ${!csvReadLineNumber}”,
“Value”: “”
},
{
“Command”: “while”,
“Target”: “"${!csvReadStatus}" == "OK"”,
“Value”: “”
},
{
“Command”: “echo”,
“Target”: “status = ${!csvReadStatus}, line = ${!csvReadLineNumber}”,
“Value”: “”
},
{
“Command”: “store”,
“Target”: “true”,
“Value”: “!errorIgnore”
},
{
“Command”: “storeAttribute”,
“Target”: “//div[@class=‘giveHeight’]/table/tbody/tr/td[text()=${!COL1}]/following-sibling::td[text()=${!COL2}]/following-sibling::td/a@href”,
“Value”: “url”
},
{
“Command”: “if”,
“Target”: “${!LastCommandOK}”,
“Value”: “”
},
{
“Command”: “selectWindow”,
“Target”: “tab=open”,
“Value”: “https://www.carsarrive.com${url}”
},
{
“Command”: “clickAndWait”,
“Target”: “css=input.button”,
“Value”: “”
},
{
“Command”: “selectWindow”,
“Target”: “tab=0”,
“Value”: “”
},
{
“Command”: “selectWindow”,
“Target”: “tab=closeallother”,
“Value”: “”
},
{
“Command”: “endif”,
“Target”: “”,
“Value”: “”
},
{
“Command”: “storeEval”,
“Target”: “${!csvReadLineNumber}+1”,
“Value”: “!csvReadLineNumber”
},
{
“Command”: “store”,
“Target”: “true”,
“Value”: “!errorIgnore”
},
{
“Command”: “echo”,
“Target”: "Reading CSV line No. ${!csvReadLineNumber} ",
“Value”: “!errorIgnore”
},
{
“Command”: “csvRead”,
“Target”: “ReadCSVTestData.csv”,
“Value”: “”
},
{
“Command”: “store”,
“Target”: “false”,
“Value”: “!errorIgnore”
},
{
“Command”: “endWhile”,
“Target”: “”,
“Value”: “”
},
{
“Command”: “store”,
“Target”: “true”,
“Value”: “!errorIgnore”
},
{
“Command”: “refresh”,
“Target”: “”,
“Value”: “”
},
{
“Command”: “gotoLabel”,
“Target”: “start”,
“Value”: “”
}
]
}

I used the DemoReadCSVwithWhile file to make a test. I added a LABEL on top, and a GotoLabel at the end => it loops forever.

However, once the variable !csvReadStatus is equal to “end_of_file” and it is read-only a can’t start reading the file again.

What error message do you get? As mentioned above, re-reading the same file again works fine in my test.

Log file says:

Reading CSV line No. 3
[echo]
status = OK, line = 3
[echo]
Reading CSV line No. 4
[error][ignored]
end of csv file reached
[echo]
— Read CSV Test starts here —
[echo]
Status = OK, line = 1 <== works fine again
[echo]
status = OK, line = 1
[echo]
Reading CSV line No. 2

Test macro (you can copy and paste it to the Source tab for testing):

{
  "CreationDate": "2018-5-25",
  "Commands": [
    {
      "Command": "label",
      "Target": "xxxxx",
      "Value": ""
    },
    {
      "Command": "store",
      "Target": "180",
      "Value": "!timeout_macro"
    },
    {
      "Command": "store",
      "Target": "fast",
      "Value": "!replayspeed"
    },
    {
      "Command": "echo",
      "Target": "--- Read CSV Test starts here ---",
      "Value": ""
    },
    {
      "Command": "label",
      "Target": "TESTSTART",
      "Value": ""
    },
    {
      "Command": "csvRead",
      "Target": "ReadCSVTestData.csv",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "Status = ${!csvReadStatus}, line = ${!csvReadLineNumber}",
      "Value": ""
    },
    {
      "Command": "while",
      "Target": "\"${!csvReadStatus}\" == \"OK\"",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "status = ${!csvReadStatus}, line = ${!csvReadLineNumber}",
      "Value": ""
    },
    {
      "Command": "open",
      "Target": "https://docs.google.com/forms/d/e/1FAIpQLScGWVjexH2FNzJqPACzuzBLlTWMJHgLUHjxehtU-2cJxtu6VQ/viewform",
      "Value": ""
    },
    {
      "Command": "type",
      "Target": "name=entry.933434489",
      "Value": "${!COL1}_${!csvReadLineNumber}"
    },
    {
      "Command": "type",
      "Target": "name=entry.2004105717",
      "Value": "${!COL2}"
    },
    {
      "Command": "type",
      "Target": "name=entry.1382578664",
      "Value": "${!COL3}"
    },
    {
      "Command": "clickAndWait",
      "Target": "//*[@id=\"mG61Hd\"]/div/div[2]/div[3]/div[1]/div/div/content/span",
      "Value": ""
    },
    {
      "Command": "storeEval",
      "Target": "${!csvReadLineNumber}+1",
      "Value": "!csvReadLineNumber"
    },
    {
      "Command": "store",
      "Target": "true",
      "Value": "!errorIgnore"
    },
    {
      "Command": "echo",
      "Target": "Reading CSV line No.  ${!csvReadLineNumber} ",
      "Value": "!errorIgnore"
    },
    {
      "Command": "csvRead",
      "Target": "ReadCSVTestData.csv",
      "Value": ""
    },
    {
      "Command": "store",
      "Target": "false",
      "Value": "!errorIgnore"
    },
    {
      "Command": "endWhile",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "gotoLabel",
      "Target": "xxxxx",
      "Value": ""
    }
  ]
}
1 Like