Ok, I found the issue:
-
When you use OnError #restart
, it restarts the macros completely. Technically this is exactly the same as pressing the Play button - or here the Loop button - again. That is why it starts again with !loop=1.
-
But without OnError #restart it works as it should! Then the automatic loop error handling takes over, and if one loop has an error it continues with the next loop.
In the macro below I simulate an error in loop = 3. The macro then continues with loop=4. And in loop = 4 we successfully read line 3 of the CSV file, since we keep track of the CSV line number in the variable globalCurrentLineToRead).
{
"CreationDate": "2018-6-22",
"Commands": [
{
"Command": "store",
"Target": "fast",
"Value": "!replayspeed"
},
{
"Command": "comment",
"Target": "#restart",
"Value": ""
},
{
"Command": "comment",
"Target": "The file ReadCSVTestData.csv is pre-installed with Kantu.",
"Value": ""
},
{
"Command": "if",
"Target": "${!loop}==1",
"Value": ""
},
{
"Command": "store",
"Target": "1",
"Value": "globalCurrentLineToRead"
},
{
"Command": "endif",
"Target": "",
"Value": ""
},
{
"Command": "store",
"Target": "${globalCurrentLineToRead}",
"Value": "!csvReadLineNumber"
},
{
"Command": "csvRead",
"Target": "ReadCSVTestData.csv",
"Value": ""
},
{
"Command": "open",
"Target": "https://docs.google.com/forms/d/e/1FAIpQLScGWVjexH2FNzJqPACzuzBLlTWMJHgLUHjxehtU-2cJxtu6VQ/viewform",
"Value": ""
},
{
"Command": "type",
"Target": "name=entry.933434489",
"Value": "${!COL1}"
},
{
"Command": "type",
"Target": "name=entry.2004105717",
"Value": "${!COL2}"
},
{
"Command": "if",
"Target": "${!loop}==3",
"Value": ""
},
{
"Command": "comment",
"Target": "On loop 3 we trigger an error to test",
"Value": ""
},
{
"Command": "echo",
"Target": "On loop 3 we trigger an error to test",
"Value": ""
},
{
"Command": "click",
"Target": "locatordoesnotexist",
"Value": ""
},
{
"Command": "endif",
"Target": "",
"Value": ""
},
{
"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": "${globalCurrentLineToRead}+1",
"Value": "globalCurrentLineToRead"
}
]
}