How can I execute the body of a while if an image exists?

I would like to execute the body of a while if an image exists on the page.

The first line in the body of the while would be xClick imageToBeFound…png

But I cannot figure out how to make the while expression be true/false if the “imageToBeFound” exists.

I’m looking for something like “while visualVerify imageToBeFound” but when I use that I get an error “Unexpected token”.

I guess part of my problem is I cannot find any documentation on syntax within UIV. Do I have to enclose something in quotes or parenthesis or some kind of brace?

OCR not working

 {
      "Command": "visualSearch",
      "Target": "exptp6_dpi_132.png",
      "Value": "result",
      "Description": ""
    },
    {
      "Command": "if",
      "Target": "Number(${result}) > 0",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "image found",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    }

I used a work-around. I stored a local variable ‘true’ before entering the while loop. The while checks that variable, then I re-set that local variable before the end of the while loop.

The re-setting of the local variable is to check if an image exists:

  "Command": "verify",
  "Target": "find_severity_clickonwarning_dpi_96.png",
  "Value": "warningExists",
  "Description": "Update while loop condition."

The problem I see is it throws an error when the image no longer exists. “warningExists” is updated properly and the macro exits, but how can I avoid getting the error? (Or is it meant to just ignore such errors?)

Should I be using a different way to set the “warningExists” variable?

Here is the error I get, and I get it each time the macro loops, whether find_severity_clickonwarning_dpi_96.png exists or not:

  • [info]

    Executing:  | verify | find_severity_clickonwarning_dpi_96.png | warningExists | 
    
  • [error][ignored]

    Line 9: Expected variable find_severity_clickonwarning_dpi_96.png to be warningExists, but it is undefined
    

Which “it” is undefined? I assume it=warningExists, but I set that before entering the while loop, and I’m expecting

“Command”: “verify”, “Target”: “find_severity_clickonwarning_dpi_96.png”, “Value”: “warningExists”, “Description”: “Update while loop condition.”

to set it again, so I’m thinking I should be using some other command, but which command should that be?

I got this working. Instead of “verify” it is now “XClickRelative” | “find_severity_clickonwarning_dpi_96.png”.