'Press a Button' Action Not Working

I'm trying to automate a simple process – I log in, I open a URL, then click a button. Everything works except the button click. The button has no name, so I can't use the 'Press a Button' action. I've tried 'Click Safari Link', 'Move or Click Mouse' using both the front window and found image's coordinates, 'Click at Found Image', and 'Open a URL'. Nothing is working.

Here's a screenshot of the button image:

Here's the HTML:

Upon successful button click, the URL kicks off a report and we receive an email with a link to the results in a few minutes.

Any suggestions?

Hey Michael,

Welcome to the forum!   :smile:

You can't use the Press a Button action with web pages – those are web generated objects and are not subject to the normal rules of macOS apps.

Please don't post screenshots of code – copy the actual code, paste it into the forum editor, then use theimage (preformatted text) button to make sure it displays properly.

When you post pictures of code, someone has to copy it by hand to work with it...

See this link for more information:

Code Block Fencing on the Keyboard Maestro Forum and Paste AppleScript as Markdown Macro


Try running this in a Execute a JavaScript in Front Browser action:

document.querySelector('a.button.button--orange.mt-1').click()

You also have to make sure JavaScript is allowed from Apple-Events.

Turn the Develop menu on in the Advanced tab of Safari's Preferences.

image

--
Take Care,
Chris

Hi Chris,

Thanks for the quick reply. I tried your suggestions however it did not work. Any other ideas?

MusicMann Studios
Michael Mann
President
T: 414.403.8219
W: www.musicmannstudios.com

I'd have to be able to tinker with the page.

If it's proprietary you could save it as a Safari webarchive, zip it, and either PM me on the forum or send it direct.

-Chris

Hey Michael,

I received the webarchive and got something working here.

Click Button [Export Your Listings] in Safari v1.00.kmmacros (5.8 KB)
Keyboard Maestro Export

It uses exactly the same JavaScript I posted above, so I'm puzzled that it didn't work for you before.

Safari must be frontmost.

You DO have “Allow JavaScript from Apple Events” turned ON – yes?

Make sure you enable the macro after importing it.

-Chris