Foreach issue: target must be an array

{
“Name”: “testMacro”,
“CreationDate”: “2023-3-26”,
“Commands”: [
{
“Command”: “executeScript”,
“Target”: “function getEnabledElements() {\n var arrElements =;\n document.querySelectorAll(".startdates.tariff_filter .data-box:not(.disabled)").forEach(function(res) {\n arrElements.push(res);\n });\n return arrElements;\n}\n\n\nreturn (getEnabledElements())”,
“Value”: “arrElements”,
“Description”: “”
},
{
“Command”: “forEach”,
“Target”: “${arrElements}”,
“Value”: “strArr”,
“Description”: “”
},
{
“Command”: “echo”,
“Target”: “${strArr}”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “end”,
“Target”: “”,
“Value”: “”,
“Description”: “”
}
]
}

Here is my test script. When executing the foreach, it throws the error:

  • [error] [Line 2] target must be an array

I run the script in chrome extension RPA 8.3.1. But I can run this javascript in console and it works well. What’s the problem?

Can you please create a similar macro that we can on a public website? Then we can debug this here and find out more.

I updated the script:
{
“Name”: “testMacro”,
“CreationDate”: “2023-3-27”,
“Commands”: [
{
“Command”: “comment”,
“Target”: “executeScript // function getEnabledElements() {\n var arrElements =;\n document.querySelectorAll(".startdates.tariff_filter .data-box:not(.disabled)").forEach(function(res) {\n arrElements.push(res);\n });\n return arrElements;\n}\n\n\nreturn (getEnabledElements());”,
“Value”: “arrElements”,
“Description”: “”
},
{
“Command”: “open”,
“Target”: “Foreach issue: target must be an array”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “executeScript”,
“Target”: “function getEnabledElements() {\n var arrElements =;\n document.querySelectorAll(".link-top-line.topic-statuses").forEach(function(res) {\n arrElements.push(res);\n });\n return arrElements;\n}\n\n\nreturn (getEnabledElements());”,
“Value”: “arrElements”,
“Description”: “”
},
{
“Command”: “forEach”,
“Target”: “${arrElements}”,
“Value”: “strArr”,
“Description”: “”
},
{
“Command”: “echo”,
“Target”: “${strArr}”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “end”,
“Target”: “”,
“Value”: “”,
“Description”: “”
}
]
}

Although it returns an empty array, it’s recognized as an array. While in the RPA, it is not.

I should use like this:
{
“Command”: “forEach”,
“Target”: “arrElements”,
“Value”: “strArr”,
“Description”: “”
},
And it works.

1 Like