How to check if a variable contains a value? Cant use if_v2 after update for Firefox (ver.9), also cant use if + .contains or .includes

Please help, i don’t know how to check if a variable contains a value

This is example of previous version of my code. It worked fine before updating

{
  "Name": "2",
  "CreationDate": "2024-5-2",
  "Commands": [
    {
      "Command": "store",
      "Target": "X",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "text",
      "Value": "X",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${X}",
      "Value": "green",
      "Description": ""
    },
    {
      "Command": "if_v2",
      "Target": "${X}.contains (\"text\") ",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "found",
      "Value": "green",
      "Description": ""
    },
    {
      "Command": "else",
      "Target": "not found",
      "Value": "red",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    }
  ]
}

Now i trying to use “if” but still cant start macros.


* [info]

Executing: | store | X | |

* [info]

Executing: | store | text | X |

* [info]

Executing: | echo | ${X} | green |

* [echo]

text

* [info]

Executing: | if | ${X}.includes ("text") | |

* [error]

[Line 4](moz-extension://fda11581-9ac7-47b5-abae-28699ca9ab03/popup.html?from=bookmark#): undefined is not a function

* [info]

Macro failed (Runtime 1.21s)

Also I can’t use this:

{
  "Command": "executeScript_Sandbox",
  "Target": "if (${X}.indexOf('text') > -1) { 'found' } else { 'not found' }",
  "Value": "output",
  "Description": ""
},
{
  "Command": "echo",
  "Target": "${output}",
  "Value": "green",
  "Description": ""
}

(undefined is not a function)

or this

{
  "Command": "executeScript_Sandbox",
  "Target": "if (${X}.indexOf('text') > -1) { 'found' } else { 'not found' }",
  "Value": "output",
  "Description": ""
},
{
  "Command": "echo",
  "Target": "${output}",
  "Value": "green",
  "Description": ""
}

(can’t convert undefined to object)

...
    {
      "Command": "if",
      "Target": "${X}.indexOf(\"text\")",
      "Value": "",
      "Description": ""
    },
...

not working correctly too

Thanks for reporting this issue and for providing a very useful test macro. The core problem seems to be similar to this one, we are looking into it right now.

As a quick workaround, you can downgrade to v6.2.6.

1 Like

Actually, I spoke to soon! Your sample macro also fails in Chrome. The correct way to check if a string includes another string is this method and it works fine:

{
  "Name": "stringcheck",
  "CreationDate": "2024-5-2",
  "Commands": [
    {
      "Command": "store",
      "Target": "test tim meyer",
      "Value": "e",
      "Description": ""
    },
    {
      "Command": "if",
      "Target": "${e}.lastIndexOf(\"tim\") > -1",
      "Value": "",
      "Description": "the return value of .lastIndexOf() is -1 if the substring is not found in the string at all."
    },
    {
      "Command": "echo",
      "Target": "yes, it contains this string",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    }
  ]
}
1 Like

Thanks a lot for solution. But just 1 question please! Where could I find this without posting on forum? Does this require knowledge of Javascript or is it available in the official ui vision documentation?

Good question. The part ${e}.lastIndexOf(\"tim\") > -1 is indeed Javascript. You can find it by searching the forum, or you can ask ChatGPT4. It knows quite a lot about Ui.Vision.

Or simply ask in the forum, this is what the forum is for :slight_smile: