How Can I Detect When an "Execute JavaScript Action" Fails to Find and Click It's Target?

I am attempting to click this "Yes" button.

XPath was not completely reliable, as different versions of the page would sometimes have a slightly different XPath.

It's all wizardry to me; however, I remembered @ccstone once mentioning that Selector Path was more reliable. I am now using Selector Path and it is working great, but I'm worried it is not 100% reliable.

Proceeding without clicking the button is a major issue. I would like to be alerted if the JS fails to find/click that button.

Here is my action currently:


If I intentionally foul the selector path, the button is not clicked, and I get the same results:


How can I detect when "Execute JavaScript Action" fails to find the button in question, so I can stop the macro and manually click the button? (And then of couse dig in and refine the macro! hah!)

Thank you!

The JS Path you've got there is extremely verbose (and pedantic) – those can frequently be abbreviated quite a lot.

I don't think I'd say QuerySelector is inherently superior to XPath – it's just different, and I understand it a little better.

I confess I'm not well acquainted with the syntactic niceties of JS Paths and usually just tinker to see if I can shorten them. (I'd have to see your page and tinker with the code to determine if I could successfully shorten the query.)

As for testing for the existence of a DOM element see @JMichaelTX's macro here:

Right at the beginning of the first JavaScript action is such a test.

No JS guru, but a Try/Catch? With a (literally!) nonsense selector, along with an alert in the browser window for a visual indicator while testing:

Catch JS Error.kmmacros (3.2 KB)

1 Like