Mutiple replace of values in same macro code

@thecoder2012 @Timo @Plankton @ulrich

I need a solution to replace multiple value in same macro code

I made an example:

I have a csv with the number of months from 1 to 12 sometime I need to replace in some macros the number of month with the month’s name example for 1 I need to use in the macro January, for 2 I need to use in the macro February, for 12 I need to use in the macro December.

I can replace 1 single value, exist a better solution to replace multiple value in same times in the macro code ?

My variable values
1
2
3
4
5
6
7
8
9
10
11
12

Replaced in

January
February
March
April
May
June
July
August
September
October
November
December

actually for 1 single replacement i use this code

{
“Name”: “replace_variable”,
“CreationDate”: “2019-12-9”,
“Commands”: [
{
“Command”: “store”,
“Target”: “1”,
“Value”: “Var1”
},
{
“Command”: “if_v2”,
“Target”: “${Var1} == "1"”,
“Value”: “”
},
{
“Command”: “store”,
“Target”: “January”,
“Value”: “Var1”
},
{
“Command”: “echo”,
“Target”: “${Var1}”,
“Value”: “#shownotification
},
{
“Command”: “end”,
“Target”: “”,
“Value”: “”
}
]
}

To replace all months i need 12 if condition, exist a simple solution ?

Thanks

Learn better Javascript. With Javascript and executeScript or executeScript_sandbox.
See executeScript, execute script, Arrays - Selenium IDE Commands Tutorial

Example:

{
  "Name": "replace-variable",
  "CreationDate": "2019-12-9",
  "Commands": [
    {
      "Command": "store",
      "Target": "var newval = \"\";var m = [\"\",\"January\",\"February\",\"March\",\"April\",\"May\",\"June\",\"July\",\"August\",\"September\",\"October\",\"November\",\"December\"];for(var i=0;i<m.length;i++){if(i == mycheck){newval = m[i];}}",
      "Value": "replace_month"
    },
    {
      "Command": "store",
      "Target": "5",
      "Value": "Var1"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var mycheck = Number ${Var1};eval ${replace_month};return newval;",
      "Value": "shownotification"
    },
    {
      "Command": "echo",
      "Target": "${shownotification}",
      "Value": ""
    }
  ]
}
1 Like

You’re great your code works great, thank you so much for the help :smiley: