Download a report from a webpage when report status is available

Hello,

I'm just starting out on Keyboard Maestro :slight_smile:

Using Chrome and after clicking the "Request report" button to launch the creation of the report, I need to (1) check if the report is available or in pending state (can take several minutes before being available) :

(2) download the report if the download button is available (only the last report, not the older).

According to you, what would be the best way to do this ?

Thanks for your help !

Hello, welcome to the forum.

One of the experts here might be able to suggest a way using JSON or JXA. :exploding_head: Then you would have to work out the rest of your macro around that.

I don't think this is a project for a beginner in KM (or even an intermediate user) but perhaps someone can at least point you towards a previous discussion about this sort of task. Perhaps it's easier than I think. :wink:

Hello Kevin,

Thanks for your answer.
I was thinking of comparing the value of the "processing" or "Download report" button attribute and setting a condition, but that doesn't seem to be the best solution (I was also thinking of using OCR).

I'll wait for an expert opinion :slight_smile:

1 Like

If you view the source, you could use JXA to get the value if you can specifically identify that button out of all the buttons. Sometimes I can muddle through that myself, but I usually rely on ChatGPT to help me out, or ask an expert here :).

Using Found Image, though, I think it would be relatively straightforward. Use a Pause Until Conditions are Met action, with the condition set to "The screen" "contains" "image", and the image set to this:

image

Without your added red highlight, of course :). And you'll want to capture it on the actual page, not from a screenshot of the page. Just use Shift-Cmd-Ctrl-4 to capture a region to the clipboard, then paste into KM.

This should make the macro pause until the Processing message has been replaced by Download Report.

EDIT: Then you can use a click at within the found image to actually click the button.

It's not nearly as slick (or foolproof) as a JXA solution, but in this case, because you can tie the button below to the static text above, it should work quite well.

-rob.

2 Likes

"Find Image on Screen" was my first thought, but my second thought was that it would find one of the existing "Download report" buttons while the first button was still showing "Processing".

However, I have now revised the wiki entry for Found Image on Screen and I conclude that the trick in this case would be to select "Topmost" in the drop-down menu (it is set to "Unique" by default). That's if @Tony_Dessablons always wants the topmost report. Is that how you see this too, @griffman?

1 Like

If you look at my image, it includes the header above the report section, as you're going to always want to click the first button below the header, right? So the idea is to just watch for that image to appear—meaning the download is ready—then click at some location from the top of the same found image to click the button.

-rob.

2 Likes

Thank you so much for your help @kevinb and @griffman.
It's working with Find_Image_on_Screen, I insert a Type_keystroke to refresh the page and a Pause as the page do not refresh itself :

Thanks !

1 Like

Glad to help, and glad you got it working!

-rob.

1 Like