Check if image exists within a particular element

Hi there, I’ve been using UI Vision to create macros for a couple of weeks and have started to develop some great timesavers on projects I’m working on.

I’m a little stuck theoretically on how to approach a problem I have.

In my macro, I iterate through a set of table rows and perform a set of actions in each loop. However, in this table row, there is a small SVG icon (a checkmark or cross) which tells me whether I should be performing the action for any given row.

So far, i’ve managed to identify whether the icon is a checkmark or cross by using the VisualSearch / Assert functions. However, as I want to check dynamically in each table row itself, I was wondering how I would best approach writing an if statement within a particular table element only.

I.e, if the checkbox image exists in a particular (nth) table row div element, then execute this function.

Maybe I’m missing something obvious but any theoretical pointers would be appreciated.

Here is a macro to scrape images from a table, maybe that helps. In this example, the macro extracts all flag images from the table:

The key part is to loop over the xpath for each image:

xpath=//*[@id=“mw-content-text”]/div/table/tbody/tr[${row}]/td/span/span/span/img

{
  "Name": "table scrape images",
  "CreationDate": "2024-12-23",
  "Commands": [
    {
      "Command": "store",
      "Target": "fast",
      "Value": "!replayspeed",
      "Description": ""
    },
    {
      "Command": "open",
      "Target": "https://en.wikipedia.org/wiki/Solar_power_by_country",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "times",
      "Target": "10",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "${!times}",
      "Value": "i",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var a = parseInt(${i}); return a +1;",
      "Value": "row",
      "Description": "Add one because table header is technically row = 1"
    },
    {
      "Command": "echo",
      "Target": "We are in row = ${row} (including header)",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "storeImage",
      "Target": "xpath=//*[@id=\"mw-content-text\"]/div/table/tbody/tr[${row}]/td/span/span/span/img",
      "Value": "flag_row${i}.png",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "All done",
      "Value": "green",
      "Description": ""
    }
  ]
}

If that does not help, a screenshot of your table will be helpful to better understand the project.