How can I get KM to find these images on a page?

I am trying to get KM to find either of these images and it cannot.
Sometimes there may be 3 or 4 of them, I would like it to find the bottommost image.
Any suggestions?

Screenshot 2024-07-01 at 2.58.16 PM

           or this image

Screenshot 2024-07-01 at 2.59.00 PM

Is the "Bottommost" option not working for you?

How are you adding the images? If it's via saving to a file, try capturing the image with ⇧⌃⌘4 then dragging to put the image on the clipboard then paste directly into the image well.

hey Nige,,,, thanx...
I use Shift+Command+NL4 to take an 'area' screenshot, then I drag that image to the image well.
I re-took the image and now if I set the 'tolerance' to 75% with 'display' on, it shows 2 positive and like 10 false responses. Anything below the 75% area then it shows nothing.
I had tried in 'area' and now am using front window, no difference really.

A web page ?

Have you experimented with finding the corresponding elements via JS ?

(Graphic searches are, of course, always a bit fragile and expensive)

Yes a web page.
I have not tried JS, can you point me to ‘the beginners guide’ for such? :smirk:

Include the CTRL key so the screen shot goes to the clipboard, and simply click on the image well and paste instead of dragging the image file in.

There's been quite a few threads where people have had DPI issues with images added by file but not when added by pasting. I'm wondering if you are having the same problem, and compensating with extra fuzz leads to too many false positives.

woof!, wow, what a difference, as always, thank you Nige....
I'm not done with the programming for the ultimate macro that I need but I am well on the way with your excellent input....
Cheers

The JS itself is not elaborate, just something like:

document.querySelector(kmvar.local_Selector).click()

in an action like

where the value of local_Selector might be, for the case of the search loupe at top right of a Keyboard Maestro Discourse page like this:

#search-button


The trick is to find the selector (or selector path) string for a particular clickable element on a web page by:

  1. Ctrl-clicking it
  2. Choosing Inspect or Inspect Element (depending on the browser)
  3. Looking at the highlit HTML for the id value (e.g. id="search-button")
  4. Using the id string, prefixed by a #, as the selector string

So, if you have a KM discourse page open in Safari, you can click on its Search button (by ID rather than graphic image) with something like:

Click on Web page element by its selector path.kmmacros (3.6 KB)


Great, I’ll give it a shot later. I was doing some of this 4-5 years ago but it was ‘buggy’ to me so i stopped.

Is it possible to move the mouse to the element and not click it?

And how will it deal with numerous occurrences on the page?

Cheers

Reading the (browser window) coordinates from the selected element should be fine

Element: getBoundingClientRect() method - Web APIs | MDN

but positioning the mouse cursor within JS is more ambitious.

Element ids will tend to be unique. Otherwise, in the the Inspect view of your browser, ctrl-clicking on the element of interest will show options under Copy for copying unique selectors or XPath queries, possibly including indexed offsets (i.e. nth match)

1 Like