How to increase value of the type per loop?

@newuserkantu posts refers to changing the value of an array variable. This is a somewhat more advanced topic.

Since you simply need to increment a Selenium IDE variable just use this:

executeScript_Sandbox | Number (${i}) + 1 | i

Note that we need the “Number ()” function to make sure that Javascript treats the content of the variable i as number (so 1+1 = 2), otherwise (as string) we would get “1+1=11” :wink:

    {
      "Name": "Increment variable",
      "CreationDate": "2021-3-17",
      "Commands": [
        {
          "Command": "store",
          "Target": "1",
          "Value": "i"
        },
        {
          "Command": "while_v2",
          "Target": "${i} <= 5",
          "Value": ""
        },
        {
          "Command": "echo",
          "Target": "i=${i}",
          "Value": "green"
        },
        {
          "Command": "executeScript_Sandbox",
          "Target": "return Number (${i}) + 1;",
          "Value": "i"
        },
        {
          "Command": "end",
          "Target": "",
          "Value": ""
        }
      ]
    }

Macro result:

Related post: Incrementing each loop - #3 by ulrich

1 Like