IF topmost image OR topmost other image, can I click found image?

I've pored over the forum and the wiki and the closest that I've found to my problem is How To Search For Multiple “Found Image” Actions, but that's simplistic compared to what I'm trying to do.

What I would like to be able to do is combine the "If image is on the screen" with finding the Topmost image and save that location to a variable, all at once. But that does not seem possible.

I have two possible logo images that I'm looking for, and either will appear multiple times on the page. Older pages have only the older logo and newer pages have the newer logo. Mixed pages are rare enough to deal with manually, without KBM help.

I want to be able to click on the topmost logo that appears, regardless of which type it is.

So far, my logic appears to have to be:

First, I have have an If-Then-Else where I first look for one logo and if it's not found, in the Else clause I look for the second logo.

In either branch, If or Else, I then look for that branch's logo a second time using Find Image to be able to save the location in a variable to be able to click on it.

No matter how I think about it, it appears that I need to look for the image twice, once to determine which logo I'm looking for and a second time to find the topmost one and save it's location.

I can't just look first for one and then the other because if the location is saved by the first Find Image, that will be clobbered when the second Find Image fails.

My thought is that I only want to look for an image once because the internal logic runs a whole lot faster than finding an image. Or is that my imagination? If the coding were simpler to just look for the same image over and over and over, would that really slow things down much?

Any comments on the logic or the performance issues?

Thanks.

AFK, but maybe try:

  1. Find imageA, set a short timeout, and save Topmost image location as variables. Also, set it as Do Not Abort Macro.
  2. do the same for imageB
  3. If variables for imageA exist, do actionsA, and same for B; i.e a Switch action.
1 Like

If I understand you right (which can be difficult from just a textual description of the issue; screenshots demonstrating the problem situation and uploading the current macro you have are a much faster and more effective way of getting the help you need, as outlined here: Tip: How Do I Get The Best Answer in the Shortest Time?) I think you might be overcomplicating this. What about something like this example macro, which clicks on whichever of the two images specified in its conditions?

Example Macro.kmmacros (48.4 KB)

2 Likes

Thanks Gabe,

Close, but I've already been there.

The issue is that when either image is present, there may be as many as 20 or 30 instances on the page and I want to find the topmost one. Your method would work if it only appeared once, but how do I trust that %FoundImage% contains the location of the topmost image? That's not an option when using "If ⇳any of the following are true:".

Can you suggest wording changes to the question to make that clearer?

Here's a clip from where the old logo is used:
image

And here's one where the new logo is used:
image

I want to find the topmost instance where there are two logos close together, on consecutive lines. In the "older" image, that happens consistently, in the "newer" image, some are like that and some already have annotation lines added. I'm trying to automate the adding of annotation lines.

Thanks,
August

Thanks, the screenshots together with that description made the problem much clearer. This new macro I tried putting together isn't foolproof, but it might get you most of the way there, especially once you've put in the images you're using and adjusted the matching fuzziness:

Example Macro.kmmacros (653.4 KB)

The idea is to use the two For Each actions to scan the screen from top to bottom for matching images, then stop after the first match and save that match's screen coordinates to a variable. If both images are on the screen, it should use their corresponding variables to compare their Y coordinate values and click on the one that's lower (i.e. closer to the the top). Again, you'll probably need to tweak and adjust this to get it to where you want, and even then it might not get you all the way there, but it should hopefully be a start.

1 Like

Thanks Gabe. I'm going to have to take some time to walk through this in detail.

I didn't know that it was possible to make ALL the found images into a collection that you could then step through one at a time. That opens up lots of possibilities, not just in this macro. That method might actually allow me to cover more "edge cases" than my previous method and thus require fewer manual interventions.

What I have been doing so far is to simply look for the topmost instance of two logos close together, as a single image.

What's going on with your using large versions of the logo and then allowing more fuzziness?

Thanks,
August

Glad to hear the Found Images collection idea proved useful. As you've probably seen by now, it lets you choose the direction with which the macro goes through matching images, so it seemed like the right tool for the job here. As for the large versions I used, I didn't have your working environment to test with, so I just approximated it with a DuckDuckGo image search for the Facebook logo. As I said before, you'll want to plug in the images you're already using, and you may need to adjust the fuzziness as well to match your system, but hopefully you'll end up with better results once you have.

By the way, one other idea that occurred to me as to how you could go about this. If the app you need this for is, or could be, kept in a fixed position on the screen, you could limit the Found Image search area to only the area where the topmost image would be located, and then make do with a much simpler "if any of the following are true" condition that looks for either image and clicks in that area if the condition is met.

1 Like

Hi @hello,

Thanks for the idea. It does keep from having to look for the same image twice.

I presume that Do Not Abort Macro keeps the macro from quitting if it doesn't find the image. That's a good idea I didn't know about.

Why the need for the timeout after finding the image? Does KBM get out of sequence on things like this? I have had to set pauses to wait for app responses and screen updates, but not for saving variables. What am I missing?

Thanks,
August

The timeout in that action is so the macro continues on to the next action(s) if it doesn’t find the image.

I've never used that feature. Thanks.