lundi 6 septembre 2021

Use Automator / AppleScript to select checkboxes and click buttons in Safari

Bitten off more than I can chew with this one. It's my first time trying to use AppleScript to automate Safari (while at the same time trying to figure out HTML). I've found examples to show me how to do this and have made it work for some very simple websites, but can't make it work for the website I'm trying to use.

I'm trying to navigate this website https://app.ssm.gov.mo/healthPHD/ using Automator with AppleScript commands.

On the third page in, when I go to the Safari console and input something like document.getElementById('btnSubmit').click() to submit the form, it works just fine.

However, when I add an AppleScript command in Automator as follows, it doesn't work:

tell application "Safari"
    activate
    tell document 1
        do JavaScript "document.getElementById('btnSubmit').click();"
    end tell
end tell

Also, I'm aware of the command document.forms[0].elements[0].checked=true for selecting checkboxes, but this doesn't seem to work for the checkboxes on this website as they are nested within the various Frames and Div parts. How do I go about navigating the frames and divs so as to select some of the checkboxes on this website before issuing the submit command?

Thanks.




Aucun commentaire:

Enregistrer un commentaire