Using querySelector is much easier than using XPath, but this same approach could be used with XPath (requires modification to the JavaScript)
The best way to determine the HTML Element and the required CSS Selector is to open the web page, and right-click on the target UI element, and select "inspect".
You can use either Chrome or Safari to do this, but I recommend Chrome, even if ultimately you will be using Safari in your workflow.
If you need help with this, post a new topic with the URL and a screen shot of the UI element you want to target.
MACRO: Pause Until Web Page Element Exists [Example]
I have had inconsistent results using h1 as the Selector. The action "PAUSE Until HTML Element is Present in FrontMost Web Page" sometimes times out. The problem could be elsewhere, but my confidence in the Selector is my initial suspect.
Yes, although with such a common tag as h1 I would probably add to it with one of these: h1.D\\(ib\\)
OR div#mrt-node-Lead-3-QuoteHeader h1.D\\(ib\\)
I doubt that the CSS_Selector has anything to do with the timeout. Most likely due to something else, like slow Internet, slow web server, etc.
I would just increase the timeout to the max time you have observed it takes to load the page.
Recently I found that this macro doesn't work on my one of the pages I worked on. I found that page has an iframe that may cause this macro stops working, even though the element I am waiting for is NOT inside of that iframe. I posted here:
iframes are NOT accessible via JavaScript in Browser.
AFAIK, iframe should not cause a problem if you are NOT trying to access it.
Have you tested your JavaScript in the Chrome JavaScript console?
Sometimes complicated web pages require a bit of trial-and-error when using JavaScript.
The best way way is to test in the Chrome JavaScript console.
This macro works for the frontmost web page, is it possible to wait element on the specific tab of the browser instead of the front most page? This would be super helpful for some slow loading webpages so that we can do something else by switch to other apps and don't have to wait on the browser.
Since this macro uses the KM JavaScript in Front Browser, and KM does not support JavaScript in browser pages/windows that are NOT frontmost, it would require a script (AppleScript or JXA) to address non-front tabs.
This is doable, but complex, and beyond the scope of this macro.
So it would be a task that the user would need to do.