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.

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": ""
    }
  ]
}

Note: If you replace visualSearch with OCRSearch in the above macro, you can use the same code to wait for text to disappear (or appear).

Compared to image search, OCR text search has the advantage that changing the screen resolution or switching between MacOS and Windows does not affect it.

Hmm,

I feel the “waitForElementNotVisible” command is much more efficient.
I’m basically have a spinner animated image wrapped in a < h3 id=‘spinner-title’> Tag while the page is doing a search.
Now I’m just checking when this specific < h3 id=‘spinner-title’> disappears.

{
“Command”: “waitForElementNotVisible”,
“Target”: “xpath=(//h3[@id=‘spinner-title’])”,
“Value”: “-> WAIT WHILE SPINNER RUNS TO FIND RESULT”,
“Description”: “”
},

Totally agree! If you can find a working xpath locator, then this is better than using a computer vision or OCR. But sometimes finding an xpath is tricky, for example if the part you need to monitor is inside an iframe.

Also, sometimes I have some “quick and dirty” automation tasks where the macro runtime or efficiency is not crucial. For these RPA tasks I tend to use computer vision instead because it makes creating the automation much faster :wink:

Lately I even experiment with the new aiPrompt and aiComputerUse commands. Their big downside is that you need to buy anthropic api credits. so that is only good for tasks that need to run only once or twice or it becomes really expensive. But for these one off tasks, it makes creating the macro even faster.