How to count? In table view, if I start to enter command storeEval, it doesn't exist in the list

I’m using Table View and I’m trying to increment a variable but when I start to enter storeEval it doesn’t show up in the list, only “store” shows up.

So, I switched to JSON view and entered “storeEval” for the command but when I switched back to table view it showed as “storeEval_depreciated”.

So, what do I use to increment (do math) on a variable?

I tried “Command”: “store”, “Target”: “${warningCount}+1”, “Value”: “warningCount”,

But when I echoed the result, it gave me “Warning count = 1+1+1”. I can count those to know I did indeed have three warnings, but if I have 23 warnings, counting like that isn’t appropriate.

What do I use to count occurrences?

storeEval_depreciated

The storeEval command is deprecated, I guess you found it in some older forum posts, maybe?

Please use the new executeScript. Old macros with storeEval continue to work without any change.

What is the difference between storeEval and executeScript?

Both commands evaluate Javascript in the context of the website. There are three main differences. First, with executeScript variables are not in quotation marks. Second, you need to add a “return” command if you want to return a result. And third, storedVars is no longer required.

Example (generate a random number between 0 and ${max}):

storeEval | Math.floor(Math.random()* Number ("${max}") | randomNumber

becomes

executeScript | return Math.floor(Math.random()* Number (${max}); | randomNumber

How to count?

For this, you can use executeScript , but better would be executeScriptSandbox (which does not interact with the website).

Example: Increase the value of i by one:

executeScriptSandbox | return Number (${i}) + 1; | i

I tried to use what you suggested, as below, but I get “Unexpected token “r”(\u{72}), …““Target”: return Num”… is not valid JSON“

  "Command": "executeScriptSandbox",
  "Target": return Number (${warningCount})+1;,
  "Value": warningCount,

What does > “r”(\u{72}) < mean, or help to determine what’s wrong?


I did a DuckDGo search for the error and got from some “assistant” “The string r"(\u{72})" is not valid JSON because JSON does not support raw string notation or escape sequences like \u{}. Instead, valid JSON requires Unicode characters to be represented as "\u0072" for the character ‘r’.

I don’t really know what it thinks is there to throw the error as I’m not using control characters, just straight keyboard characters.

Well, I looked at the DemoExcecuteScript macro and it is formated quite differently than the examples given for excecuteScript in the Selenium IDE command list.

This did not give me an error when I tried to switch back to Table View:

{
  "Command": "executeScriptSandbox",
  "Target": "return (Number (${warningCount})+1)",
  "Value": "warningCount",
  "Description": "Counted." 
},

I had to remove the semicolon, and add parenthesis after 'return', before Number, and after the +1.

I also had to add quotes around the Value "warningCount", and the Target line, which stopped the “r”(\u{72}), …““Target”: return Num”… is not valid JSON“ error I got above.
------------------------
Even so, when I ran the macro I got "Line 16: Command executeScriptSandbox not supported yet".

I'm running UI.Vision IDE 9.5.3 - is there a later version I should use?

Well, changing executeScriptSandbox to executeScript worked.

What is needed to use executeScriptSandbox? Am I missing some module?

it doesnt work sometimes