|Command|Target|Value|
|execute script|return []|arrayA |
|While|i<=10||
|store|xpath=//table/field[i]|numberA|
|store|numberA|arrayA|
|execute script|return i+1|i|
|end|||
How can I add the element value into array by running variable?
|Command|Target|Value|
|execute script|return []|arrayA |
|While|i<=10||
|store|xpath=//table/field[i]|numberA|
|store|numberA|arrayA|
|execute script|return i+1|i|
|end|||
How can I add the element value into array by running variable?
You can not use the store
command to assign a value to an array. It must be done with executeScript, since array handling can only be done in Javascript (JS):
var newArr = ${array1};
Assign the Selenium IDE variable “array1” (it has the array) to a JS array “newArr”newArr[2][1] = 'New value';
Assign the new value to the JS array cell (2,1) return newArr
Store the modified JS array back to the Selenium variable array1
Here are all the steps inside one Execute Script
command:
{
"Command": "executeScript_Sandbox",
"Target": "var newArr = ${array1}; newArr[2][1] = 'New value'; return newArr",
"Value": "array1"
},
Please see
Thanks Ulrich for your help, the problem solved.
I use a simple solution to add value in array
With store i add values in array and after i can use it like variables see my macro code
Macro code
{
"Name": "Array",
"CreationDate": "2021-1-20",
"Commands": [
{
"Command": "store",
"Target": "AAAAA",
"Value": "Var1"
},
{
"Command": "store",
"Target": "BBBBB",
"Value": "Var2"
},
{
"Command": "executeScript_Sandbox",
"Target": "return [\"\",${Var1},${Var2}];",
"Value": "Array"
},
{
"Command": "echo",
"Target": "${Array[1]}",
"Value": "#shownotification"
},
{
"Command": "echo",
"Target": "${Array[2]}",
"Value": "#shownotification"
}
]
}
@newuserkantu This is a nice way to add a new value to the array, thanks! Just to clarify for everyone: My post above is how to change an already existing value in the array.
I add the first value empty to start value from 1 (I can combine it with loop and times)
I use in this mode bypassing 0 array value
${Array[${!LOOP}]}
In this mode i can use all array value inside loop or times.
With this solution you can store more variables empty and after you can update with store and use in array, you can do all work.