Search for Text, if Not Found, Open Next Page and Search Again

Say I have 200 hundred web pages of products to sift through, to find a specific product.

I'm looking for a string of text (i.e. carpet_853.jpg), but I don't know which of those 200 pages that product will be on.

I'm trying to build a macro to:

  1. Find (command+F) the string I'm looking for on the first web page
  2. If it doesn't find the product, load the next web page (page 2). Continue until...
  3. if it does find the product, stop the macro and tell me it found it

Attached is what I have, but I can't figure out how to combine an "Until" macro with an "If/Then" macro. Can anyone please help me?

This would at least help me find one product at a time, but in truth, I have more than one product to look for at the same time.

1 Like

Put the action, referencing the web pages loading macro, at the beginning of the Execute the following action block. Your only concern would be to ensure that the input, consisting of the series of web pages, is available.

1 Like

Hey Bret,

You can do this much more efficiently with some JavaScript.


That did it, thank you!

I don't know the first thing about scripting unfortunately.

Well, this macro will give you a starting point – test it on this web page.

Get Text of Front Browser's Front Page.kmmacros (7.6 KB)

Macro Image

Keyboard Maestro Export

1 Like

Cool! That's even simpler. I put it in an Until and it works great. Is it possible to feed the variable a list of strings to look for on each page? That would be the ultimate goal, but if it's too much hassle, I can get by with this.

Sure. How do you want the macro to identify what words have been found?

Awesome! Just a simple "Found it" spoken text would be perfect.

Attached is what I have and it's working really well looking for finding single strings.

Find Missing Thumbnail.kmmacros (7.3 KB)

Macro Image

Screen Shot 2023-02-01 at 10.09.40 AM

I'm not sure you want your macro to be hollering at you each time it finds a string. That would bug the heck out of me pretty quick...

Here's an example of running through a list of strings and displaying what was found.

Run on this page to test.

Search for a List of Strings in Text of Front Browser's Front Page v2.00.kmmacros (10 KB)

Macro Image

Keyboard Maestro Export

1 Like

LMAO that first item you listed is gold. You made my week.

Definitely works as it is.

Where do I include the "Load Next Page" macro, in the event that it doesn't find any strings? I tried putting it in either Otherwise actions, but it doesn't find the strings it's supposed to find; it will just continuously loads the next page.

I finally figured out how to use that in an Until macro. Attached is what I ended up with.

Thank you again for all of your assistance. You were great.

Macro Image


Chiming in: to avoid occasional faults, if it doesn't contain it, add Wait For _browser_name to Finish Loading right after the macro Execute Macro "Load Next Page".

1 Like