Issue with forEach command

I’ve been trying to use the forEach command for a while now. I’ve looked at all the docs, forum posts, examples, and everything. No matter what I do, I keep running into an error: [error] Line 2: target must be an array.

The sample code I am using:

{
  "Name": "forEach",
  "CreationDate": "2022-4-27",
  "Commands": [
    {
      "Command": "executeScript_Sandbox",
      "Target": "var arr = [\"Hello\",\"World\", \"2020\"]; return arr;",
      "Value": "myarray",
      "Description": ""
    },
    {
      "Command": "forEach",
      "Target": "myarray",
      "Value": "elem",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${elem}",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    }
  ]
}

The result:

I also tried this one:

{
  "Name": "forEach",
  "CreationDate": "2022-4-28",
  "Commands": [
    {
      "Command": "executeScript_Sandbox",
      "Target": "[\"Hello\",\"World\", \"2020\"];",
      "Value": "myarray",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${myarray}",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "forEach",
      "Target": "myarray",
      "Value": "elem",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${elem}",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    }
  ]
}

and got:

So it looks like the array is never actually stored. I am using the Brave browser on Windows, so the Chrome based extension.

+1 same issue here. Only popped up in the last few weeks - the same scripts have been running fine for months previously?

Arrays stopped working with executeScript_Sandbox in version 7. Easiest solution, if it works for you is to switch it to executeScript. Also, in your example, you need a return statement i.e.

    {
      "Command": "executeScript",
      "Target": "return [\"Hello\",\"World\", \"2020\"];",
      "Value": "myarray",
      "
1 Like

Thanks, that helped!

https://ui.vision/rpa/docs/selenium-ide/foreach

I am following the example but there is issue as mentioned above in the post.