How to trigger an error if an image is still there? (or: Wait until image disappears)

visualAssert stops if an image is NOT found. But I need the reverse.

The macro should trigger an error if the image is found.

The other option that would be useful is to wait until the image disappears.

Here is the solution with “visualSearch”. The macro waits until the blue banner disappears OR until the timeout of 60 seconds is reached. At t=21s in the video I click the button to hide the banner => macro no longer finds image and ends loop.

Code:

{
  "Name": "wait for image disappear",
  "CreationDate": "2022-12-11",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://www.w3schools.com/howto/howto_js_toggle_hide_show.asp",
      "Value": "i",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "1",
      "Value": "!timeout_wait",
      "Description": "Tell VisualSearch to not wait for image long"
    },
    {
      "Command": "store",
      "Target": "${!runtime}",
      "Value": "starttime",
      "Description": "Save current time"
    },
    {
      "Command": "do",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "visualSearch",
      "Target": "bluebutton_dpi_168.png",
      "Value": "i",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Number of images found: i = ${i}",
      "Value": "green",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return parseFloat(${!runtime});",
      "Value": "r",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return parseFloat(${!runtime}) - parseFloat(${starttime}) ",
      "Value": "timediff",
      "Description": "If the image does not disappear within 60 seconds, then trigger a timeout error. Remove this logic of you want to wait forever."
    },
    {
      "Command": "echo",
      "Target": "time difference between NOW and loop start = ${timediff}",
      "Value": "pink",
      "Description": ""
    },
    {
      "Command": "if_v2",
      "Target": "${timediff} > 60",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "throwError",
      "Target": "Waited too long, lets stop",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "repeatIf",
      "Target": "${i} > 0",
      "Value": "",
      "Description": "i > 0 means the image is FOUND, then we wait until it is gone "
    },
    {
      "Command": "echo",
      "Target": "Image disappeared!!!",
      "Value": "blue",
      "Description": ""
    }
  ]
}