"store Json" replacement (Migrating from SIDE Selenium IDE to Ui.Vision)

UI.Vision has no specialized store Json command, but that is not needed. The solution (found by the user himself :slight_smile: ) is to use Javascript and executeScript_Sandbox to recreate the store Json command. The demo macro below shows this. You need only 2 lines to scrape JSON. The macro first scrapes the JSON output from the browser window with storeText and the css=pre locator and then uses JSON.parse to get the required value.

{
  "Name": "scrape_json",
  "CreationDate": "2023-1-25",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://api.ocr.space/parse/imageurl?apikey=helloworld&url=http://i.imgur.com/s1JZUnd.gif&language=chs&isOverlayRequired=true",
      "Value": "",
      "Description": "Free OCR API call"
    },
    {
      "Command": "storeText",
      "Target": "css=pre",
      "Value": "page_data",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "JSON=${page_data}",
      "Value": "green",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var json_object = JSON.parse(${page_data}); return json_object.ProcessingTimeInMilliseconds",
      "Value": "ptime",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "OCR API Processing Time In Milliseconds = ${ptime}",
      "Value": "blue",
      "Description": ""
    }
  ]
}
1 Like