Selecting a dropdown menu in Safari I need to create an Applescript to open a certain website and export it as PDF using the menu &quot;Save as PDF…&quot; under the File menu. Then, I need to save that PDF on a certain location on my hard drive. I am encountering trouble trying to activate the dropdown menu in the first place.
I am trying this code but I get an error:
tell application &quot;Safari&quot; to open location &quot;http://www.webiste.com/&quot;
delay 1
    click menu item &quot;Save as PDF...&quot; of menu bar item &quot;File&quot;        
    end tell
end tell

I am adding a delay 1 to make sure all elements are loaded before firing the &quot;Save as PDF...&quot; menu.
I haven't yet reached the point of determining the specific location where I want that PDF to be stored.
I will use Automator to create a recurring event based on this apple script.
Any ideas?
Tested under macOS High Sierra, here is how I do it:
set saveToLocation to &quot;~/Documents&quot;
set myURL to &quot;http://www.webiste.com/&quot;

tell application &quot;Safari&quot;
    make new document with properties {URL:myURL}
    activate
end tell

tell application &quot;System Events&quot;
    repeat until exists (buttons of ¬
        UI elements of ¬
        groups of ¬
        toolbar 1 of ¬
        window 1 of ¬
        process &quot;Safari&quot; whose ¬
        name = &quot;Reload this page&quot;)
        delay 0.5
    end repeat
    tell application process &quot;Safari&quot;
        click menu item &quot;Export as PDF…&quot; of ¬
            menu &quot;File&quot; of ¬
            menu bar item &quot;File&quot; of ¬
            menu bar 1
        repeat until exists sheet 1 of window 1
            delay 0.05
        end repeat
        keystroke &quot;g&quot; using {shift down, command down}
        repeat until exists sheet 1 of sheet 1 of window 1
            delay 0.05
        end repeat
        set value of ¬
            combo box 1 of ¬
            sheet 1 of ¬
            sheet 1 of ¬
            window 1 to ¬
            saveToLocation
        click button &quot;Go&quot; of sheet 1 of sheet 1 of window 1
        click button &quot;Save&quot; of sheet 1 of window 1
    end tell
end tell


Note: The example AppleScript code is just that and does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.