MacOS – Applescript to automate drop-down selection in Mozilla Firefox

applescriptfirefoxmacmacos

I'm trying to automate the selection of a value from a drop-down box in Mozilla using an applescript. What I want it to do is to tab to the drop-down box and enter down twice to select the third item in the drop-down.

Here is what I have so far:

tell application "Firefox"
    tell application "System Events" to keystroke tab
    tell application "System Events" to keystroke down
    tell application "System Events" to keystroke down
end tell

But, as far as I can tell, when I run the script nothing happens.

What do I need to do to make this script work?

EDIT: I have also tried entering the key code 125 for down in case the keystroke command was wrong.

Best Answer

Try this

tell application "Firefox"
    activate
    tell application "System Events"
        keystroke tab
        keystroke (key code 125)
        keystroke (key code 125)
        keystroke (key code 125)        
    end tell
end tell

You might not need to activate Firefox if it's the current active app. Them you just need :

tell application "System Events"
    keystroke tab
    keystroke (key code 125)
    keystroke (key code 125)
    keystroke (key code 125)        
end tell