Problem with random variables

Hi,

I need some help because it returns me this, and i don’t get why :cry: :

[error] [Line 7] : Error in runEval code: Unexpected token ‘{’

Here’s the begining of my macro:

{
  "Name": "Services-Titres",
  "CreationDate": "2021-6-27",
  "Commands": [
    {
      "Command": "csvRead",
      "Target": "liste_colonne.csv",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "storeEval",
      "Target": "new Array ('test1', 'test2', 'test3')",
      "Value": "Titres",
      "Description": ""
    },
    {
      "Command": "storeEval",
      "Target": "storedVars['Titres'].length",
      "Value": "length",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "array length = ${length}",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "storeEval",
      "Target": "Math.floor(Math.random()*storedVars['length'])",
      "Value": "num",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "num=${num}",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "storeEval",
      "Target": "storedVars['Titres'][${num}]",
      "Value": "Titrehasard",
      "Description": ""

storeEval is deprecated. I highly recommend switching to exectueScript.

From the store eval docs page:

The storeEval command is deprecated. 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

In addition in the UI Vision’s Selenium IDE++ the ExecuteScript command is available as “sandboxed” version that does not run in the context of the website. This fixes a long-standing design issue of the classic Selenium IDE and avoids CSP errors. For more details see executeScript_Sandbox.

1 Like

Thx a lot for your answer!

Can you help me to adapt it, in order to pick a data form a list please? :slight_smile: