Renaming Screenshots taken from CSV file

Hi,

I have the follown script running

    {
  "Name": "Screens",
  "CreationDate": "2020-4-7",
  "Commands": [
    {
      "Command": "csvRead",
      "Target": "urls.csv",
      "Value": ""
    },
    {
      "Command": "open",
      "Target": "${!col1}",
      "Value": ""
    },
    {
      "Command": "comment",
      "Target": "Remove non alphanumeric chars from URL, so we can use it as screenshot file name",
      "Value": ""
    },
    {
      "Command": "storeEval",
      "Target": "var string = \"${!col1}\"; var stripped = string.replace(/[^A-Za-z0-9]/g, ''); stripped;",
      "Value": "alphanumericonly"
    },
    {
      "Command": "captureScreenshot",
      "Target": "screenshot_for_${alphanumericonly}",
      "Value": ""
    },
    {
      "Command": "localStorageExport",
      "Target": "screenshot_for_${alphanumericonly}.png",
      "Value": ""
    }
  ]
}

It reads a CSV loops through the URLs and then takes a screenshot.
I would like to name the screenshot as the following pattern.

https://www.abc.com = abc.png

Strip the https://www and everything after it encounters a dot.

I changed the script from storeEval to executeScript_Sandbox and now it runs ok. But something still needs to be improved with your regular expression, because now I get “screenshot_for_httpsuivisionrpadocsseleniumideforeach.png” - so stripping some parts of the URL is still missing.

{
  "Name": "test",
  "CreationDate": "2020-4-8",
  "Commands": [
    {
      "Command": "comment",
      "Target": "csvRead // urls.csv",
      "Value": ""
    },
    {
      "Command": "store",
      "Target": "https://ui.vision/rpa/docs/selenium-ide/foreach",
      "Value": "col1"
    },
    {
      "Command": "open",
      "Target": "${col1}",
      "Value": ""
    },
    {
      "Command": "comment",
      "Target": "Remove non alphanumeric chars from URL, so we can use it as screenshot file name",
      "Value": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var string = ${col1}; var stripped = string.replace(/[^A-Za-z0-9]/g, ''); return stripped;",
      "Value": "alphanumericonly"
    },
    {
      "Command": "captureScreenshot",
      "Target": "screenshot_for_${alphanumericonly}",
      "Value": ""
    },
    {
      "Command": "localStorageExport",
      "Target": "screenshot_for_${alphanumericonly}.png",
      "Value": ""
    }
  ]
}

Another option would be to use XRun and simply call a script in your preferred language to remove https://www after the screenshots are saved.
For example in powershell you can do this with the commands Rename-Item - NewName -Replace “https://www”, “”
It replaces it with nothing, removing it

1 Like