(Selenium IDE) Is there a way to concatenate the results of a script into a longer string?

I need to generate a new random email each time I run my script. I know the script by itself works, but when I attempt to add the returned number into testaccount+<###>@gmail.com it fails. It doesn’t like my plus signs, but I’m pretty sure those are standard?

Command: execute script
Target: return {“testaccount+”+Math.floor(Math.random()*99999)+“@gmail.com”;}
Value: Var1

The error I get is: Unexpected token ‘+’

I would love it if someone could explain the correct way to do this.

See here:

{
      "Command": "executeScript",
      "Target": " return \"testaccount\" + Math.floor(Math.random()*99999).toString() + \"@gmail.com\";",
      "Value": "Var1",
      "Description": ""
    }
1 Like

With ui vision 6.2.6 for firefox working like a charms

I do not use ui vision for Chrome and i can not test it

Macro code:

{
  "Name": "AAAA",
  "CreationDate": "2023-2-26",
  "Commands": [
    {
      "Command": "executeScript",
      "Target": " return \"testaccount\" + Math.floor(Math.random()*99999).toString() + \"(AT)gmail.com\";",
      "Value": "Var1",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${Var1}",
      "Value": "blue",
      "Description": ""
    }
  ]
}
[status]

Playing macro AAAA

[info]

Executing:  | executeScript |  return "testaccount" + Math.floor(Math.random()*99999).toString() + "(AT)gmail.com"; | Var1 | 

[info]

Executing:  | echo | ${Var1} | blue | 

[echo]

testaccount51227(AT)gmail.com

[info]

Macro completed (Runtime 0.74s)

The solution written by @uiuser works perfectly accept it as a solution

Thanks for the help. I am still getting failed: invalid or unexpected token.

Command: execute script
Target: return "testaccount" + Math.floor(Math.random()*99999).toString() + "@gmail.com";",
Value: Var1

Selenium IDE chrome. Am I misinterpreting something you wrote?

I tested in UI Vision

I downloaded that and tested there. Same error.

Executing: | executeScript | return "testaccount" + Math.floor(Math.random()*99999).toString() + "@gmail.com";", | Var1 |

Line 8: Error in executeScript code: Invalid or unexpected token

can you record video?

No, but I have included screenshot.

use this

 return "testaccount" + Math.floor(Math.random()*99999).toString() + "@gmail.com";

Really appreciate your patience. That worked. Thanks.

1 Like