Gethino
November 13, 2020, 1:28pm
1
Hello everyone,
How do I save the “scheduled on” dates to different variables like date1, date2, and so on using a loop(not started from the loop button)?
It can be done manually but if the number of rows go higher, it will be tiresome.
{ "Command": "storeText", "Target": "xpath=//*[@id=\"0\"]/div/table/tbody/tr[${!LOOP}]/td[4]", "Value": "class" },
The text is located in the 2nd row and goes all the way to row 13.
What is the best way to get this done?
Thank you
ulrich
November 13, 2020, 8:59pm
2
Use the TIMES…END loop and then use !TIMES instead of !LOOP
And instead of using many different variables, use an array. Arrays are a bit tricky to work with, but once you have the right code in place it is actually quite easy and saves many lines of code:
Test macro:
{
"Name": "times and array",
"CreationDate": "2020-11-13",
"Commands": [
{
"Command": "comment",
"Target": "Define array",
"Value": ""
},
{
"Command": "executeScript_Sandbox",
"Target": "var arr = []; return arr",
"Value": "array1"
},
{
"Command": "times",
"Target": "3",
"Value": ""
},
{
"Command": "executeScript_Sandbox",
"Target": "var newArr = ${array1}; newArr[(${!times}-1)] = ${!times}*2; return newArr",
"Value": "array1"
},
{
"Command": "end",
"Target": "",
"Value": ""
}
]
}
Gethino
November 14, 2020, 9:32am
3
ulrich:
{
"Name": "times and array",
"CreationDate": "2020-11-13",
"Commands": [
{
"Command": "comment",
"Target": "Define array",
"Value": ""
},
{
"Command": "executeScript_Sandbox",
"Target": "var arr = []; return arr",
"Value": "array1"
},
{
"Command": "times",
"Target": "3",
"Value": ""
},
{
"Command": "executeScript_Sandbox",
"Target": "var newArr = ${array1}; newArr[(${!times}-1)] = ${!times}*2; return newArr",
"Value": "array1"
},
{
"Command": "end",
"Target": "",
"Value": ""
}
]
}
Thank you @ulrich . Arrays sound like the best way in this case. I am not very good at programming. How do I stores the dates in an array using a loop?
Thank you again for your help.
ulrich
November 14, 2020, 6:41pm
4
First store the text in a normal variable (just as you did already), and then assign this variable to the array inside executeScript_Sandbox:
1 Like