MacOS – Using Applescript to make selections from dropdown menu and Apply

applescriptmacos

I'm trying to write an Applescript that will open a webpage, change the selection in 2 dropdown menus and then click on a button to Apply the changes.
I've extracted the IDs for the 2 dropdown menus and the button using Inspect Elements on the webpage but when I try and set the values in the Dropdown menu I get a 'missing value' error.

I'm trying to set 'Daylight Saving:' (DaylightSaving1_ddlDaylightSaving) to be '1 hour' (Value 2) and 'Max Graph Size' (DaysPerGraph1_ddlDaysPerGraph) to be '1 day' (Value 1), then click the Apply button (btnModsApply)

What have I done wrong in the script?

tell application "Safari"
    tell window 1
        set current tab to (make new tab with properties {URL:"http://www.ukho.gov.uk/easytide/easytide/ShowPrediction.aspx?PortID=0036&PredictionLength=7"})
    end tell
delay 0.1
    tell document 1
        do JavaScript "document.getElementById('DaylightSaving1_ddlDaylightSaving').value=2;"
        do JavaScript "document.getElementById('DaysPerGraph1_ddlDaysPerGraph').value=1;"
        do JavaScript "document.getElementById('btnModsApply').submit()"
    end tell
end tell

Best Answer

You can use Automator instead of debugging javascript if you prefer that option.

In Automator.app you can set it up to open a new safari tab and then you can use the record feature (red button in the toolbar) to change the dropdown menu and press the button.