Adapting Java script snippet from Selenium to UI.Vision

I used Selenium for all my testing but wanted to switch to UI.Vision as it gives me very nice features that helps me a lot.

I’ve a problem though as I can’t use my old code snippet for reading vales, that are entered by the tester and split them by a defined separator.

I tried adapting my code to read csv but that means I need to generate that CSV beforehand. We also receives the data in a very specific format. Also the separator can’t be comma, and I also can’t IT handle/change the data output so we can accommodate for putting the data into “” brackets.

My Code is very basic but I can’t adapt it for UI.Vision.
I would use:
Command: execute script
Target: data = prompt("Enter CSV line from Dataset"); var csv = data.split(";"); return(csv);
Value: a

When the code is run a prompt pops up, asking for the Data. We paste the values from the CSV we’re given and the code splits the value by semicolon and afterwards save it in an array of a.

Afterwards it just fills the values from the array into specifics boxes.

Thanks for any help. And like i said, reading from csv is not going to work as we would’ve to change quit a lot in our backend to accommodate for that change.

Hi, thanks for the interesting issue. Normally executeScript should work the same in UI Vision and Selenium IDE. => Can you please post a longer Selenium IDE test script here? Then we can debug that further.

How do you then access variable a to fill the values into the form? Is it simply a[0]?

Here’s the screenshot.


I would access them with ${a[x]}. :slight_smile:

So we have two issues here:

  • Javascript prompt dialog does not display. => This is because of UI Vision’s automatic popup handling. It blocks this dialog. The solution here is to use the more flexible native PROMPT command.

  • The other issue is that the echo | ${a[0]} syntax for arrays is not supported yet. => The workaround can be to use executeScript | return ${a}[0]; | a0 to assign the array value to a normal variable. I understand that this is more cumbersome and thus I have added echo | ${a[0]} syntax support to our to-do list for the next update :slight_smile:

Tip: Since your scripts do not need to run inside the website, I recommend to use executeScript_Sandbox instead of executeScript.

    {
      "Name": "csvworkaround",
      "CreationDate": "2020-2-4",
      "Commands": [
    {
      "Command": "prompt",
      "Target": "Enter the CSV line@aaa;bbb",
      "Value": "p"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var data = ${p}; var csv = data.split(\";\"); return(csv);",
      "Value": "a"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return ${a}[0];",
      "Value": "a0"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return ${a}[1];",
      "Value": "a1"
    },
    {
      "Command": "echo",
      "Target": "${a0}",
      "Value": "blue"
    },
    {
      "Command": "echo",
      "Target": "${a1}",
      "Value": "green"
    }
      ]
    }
1 Like

Hi that’s great, it works! :smiley:
FYI: I didn’t do echo with variable, but if you want to add it for future releases, why not?

I only now have the “problem” that the code is rather slow.
Is there any possibilities I can a) speed it up an b) if I’ve a Command": “gotoIf_v2” and the target is “!${!statusOK}”, can I shorten the 10 seconds delay in any way?

Thanks again though, this is a game changer now for us!

I only now have the “problem” that the code is rather slow.

Did you use the fast replayspeed setting?
See https://ui.vision/rpa/docs#!replayspeed

if I’ve a Command": “gotoIf_v2” and the target is “!${!statusOK}”, can I shorten the 10 seconds delay in any way?

It sounds like you want to change the default page timeout value, or? This can be done with the various timeout internal variables. See the settings page:

Oh wow, that worked like a charm.
Thank you very much, now everything runs very fast and I can’t detect any issue so far.

Regards :slight_smile: