If_v2 command problem

Hello.I try to create command like this
“Command”: “if_v2”,
“Target”: “${Variable1} > [${Variable2}+200]”
But is not working.I mean with this command, system comparing only if variable 1 is greater than variable 2 and ignores the +200.Does anyone know the correct syntax ?

I recommend that you improve the formula by creating variable 3 that includes the value with the 200 added up in this way you will make a simple difference between variables. It does not seem clear to me the formula so written.

Yes i tried also .For example i created variable 3 to be 100+200 but the result was not 300 but shown as “200+100” .Maybe there is other symbol in order to summary 2 numbers and not the “+” symbol.

For example i do this
“Command”: “if_v2”,
“Target”: “${Variable1} > [{Variable2}+{Variable3}]” (var2=100 and var3=200) but on echo the result showing as “100+200” (but it should be 300) so comparing variable1 with 100 only.This seems not summary the 2 numbers [{Variable2}+{Variable3}] .

You need to use the Javascript “Number” conversion to make sure the string content is treated as number, and not as string. This works:

Number (${var1}) > Number (${var2}) + 200

Example:

{
  "Name": "greater",
  "CreationDate": "2019-9-23",
  "Commands": [
    {
      "Command": "store",
      "Target": "100",
      "Value": "var1"
    },
    {
      "Command": "store",
      "Target": "22",
      "Value": "var2"
    },
    {
      "Command": "if_v2",
      "Target": "Number (${var1}) > Number (${var2}) + 200",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "var1 wins",
      "Value": "green"
    },
    {
      "Command": "else",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "var2 wins",
      "Value": "blue"
    },
    {
      "Command": "end",
      "Target": "",
      "Value": ""
    }
  ]
}
1 Like

Thank you very much ! This makes things more simple and easy !

Hello :slight_smile: .This works fine for numbers.But is it any way when we need to compare percentages ?
I mean if i do
{
“Command”: “store”,
“Target”: “105%”,
“Value”: “var1”
},
{
“Command”: “store”,
“Target”: “20%”,
“Value”: “var2”
},
{
“Command”: “if_v2”,
“Target”: “Number ({var1}) > Number ({var2})”,
“Value”: “”
},
Then there is problem because system showing var1 is lower than var2 .
This is because reading only the first 2 numbers of amount 105% .
So reading it as 10 which is lower than 20.
If_v2 command responds good up to 99% but when goes more than 100% does not work.So is it any way to store variable as percentage to fix this ?
Also i would like to know if there is a way to store a variable as time like 12:55:00 .
Thank you !

Remove % in variable and after the result you add agains in this mode you elaborate numbers only.

Can not remove % .It takes it from webpage using storetext command :frowning:

Yes you can remove it, execute if command and after readd it, it’s simply.

If you confirm that works with number use in if_v2 number numbers only, after if you readd %

With what command to remove % sign .Is not possible.

I do not understand the problem you encounter in the macro.

When compare variables, if variable is a percentage number and not a simple number, then system counts only the first 2 digits of number instead of all the digits of number.
Example
If 88% > 20% then execute X command (and of course this is valid because 88 is greater than 20)
But if 105% > 20% then command X is not executed because system reading only the first 2 digits of 105 and reading as 10% !
So 10 is not greater than 20 so command is not executed.
Maybe a solution is to remove the % symbol from both numbers so system can read the numbers normally.
Is that clear now ?

In your code missing $ simbol.

Here you can find a correct code macro with if and working

Your code contains errors.

But this was not the code !
It was just the way of what i test.
If you want the code here it is.
If you try it you see that system finally will execute command “pause” and not command “open tab” and this is not normal.
{
“Name”: “test”,
“CreationDate”: “2019-10-9”,
“Commands”: [
{
“Command”: “store”,
“Target”: “105%”,
“Value”: “var1”
},
{
“Command”: “echo”,
“Target”: “{var1}", "Value": "" }, { "Command": "store", "Target": "20%", "Value": "var2" }, { "Command": "echo", "Target": "{var2}”,
“Value”: “”
},
{
“Command”: “if_v2”,
“Target”: “Number ({var1}) > Number ({var2})”,
“Value”: “”
},
{
“Command”: “selectWindow”,
“Target”: “tab=open”,
“Value”: “”
},
{
“Command”: “else”,
“Target”: “”,
“Value”: “”
},
{
“Command”: “pause”,
“Target”: “5000”,
“Value”: “”
},
{
“Command”: “endif”,
“Target”: “”,
“Value”: “”
}

endif is deprecated now you must use end command

https://ui.vision/docs/selenium-ide/if