Click image if


I have some rows in a web page and i want to click X, if field is highlighted in red (for all rows).

If one of the fields is highlighted in red then click X next to it

How to do it?

Using Found Image (KM Wiki) will NOT work reliably. I just tested it using this macro:

  • Multiple images are found
  • No images are found
  • The first image at the top is not found first

Found Image actions are always somewhat unreliable, but to have a good chance of working the image must be unique and distinct (high contrast).

###MACRO:   Click on First Found Image @Test

~~~ VER: 1.0    2017-06-13 ~~~

<a class="attachment" href="/uploads/default/original/2X/0/051457e6e1e9d32ac056654099c705db651770be.kmmacros">Click on First Found Image @Test.kmmacros</a> (23 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**


<img src="/uploads/default/original/2X/d/d49da5bd3916f1ad28563fd4c3aa1e64d667bbb9.png" width="478" height="791">

I’d suggest that you consider an alternate approach, like using Execute a JavaScript in Google Chrome action (KM Wiki).

If you can post the HTML code for this section of the web page, perhaps I can help.

Does clicking the (x) turn the field from Red? If so, you could perhaps do something like:

  • Repeat 9999 times
    • Find Image, not unique, to variable “Where”
    • if variable Where is empty
      • Break from Loop
    • Click Where.x+270,Where.y (absolute)
    • Maybe Pause for the (x) to clear the red

However as @JMichaelTX says, the low contrast may make it hard for Keyboard Maestro to find the image. If you can limit the screen area you are searching, then Keyboard Maestro will use a more accurate search and that will help.

If the (x) does not clear the red, then you could do something like:

  • Set y to WINDOW(Front,Top)
  • Set x to WINDOW(Front,Left) + 450 (whatever is needed to get to the column position)
  • While calculation y < WINDOW(Front,Bottom)
    • if Pixel at x,y is Red
      • click at x+270, y+10
      • while Pix at x,y is Red
        • set variable y to calculation y+1
    • else
      * set variable y to calculation y+1

Alternatively, you could assume the height of the cell as whatever it is and that would simplify things, just test each pixel every N pixels.

Fairly ugly though.

After pressing X current row will be deleted.
I have up to 150 rows with red fields, it depends on some conditions.
Every time row number is different.

The problem is that i am doing it in a Teamviewer on a windows machine. So i can use only mouse clicks, keyboard shortcuts and find and click images on a page.

My idea is to find a highlighted field then move mouse to the right until it fings X and click.

What app is running in the Teamviewer window?
Perhaps there is a command or shortcut for that app that will either select the row, select all of the rows to be deleted.

For example, Excel has a filter that will select rows by the color of the cell in a particular column. Once selected, it is easy to delete.

It’s a web browser, google chrome or firefox

If there is a way to move mouse only to the right over a certain distance after the highlighted field is found - it may solve my question.

Yes, once you have found the image, you can use the found coordinates to move the mouse.

Yes, that is exactly what I did in my above macro:

EDIT: 2017-06-14 4:19 PM CT

The first action stores the position of the image, and the next action moves and clicks the mouse 500 pixels to the right. You can combine the actions if you wish. See my post above for link to the wiki.

1 Like

Thanks a lot. I will try this!