AppleScript: how to change the value of a website options menu?

I am trying to change the value of a website options menu via AppleScript.

When I run:

tell application "Safari"
 activate
  tell current tab of window 1
   set changeValue to do JavaScript "document.getElementById('selected-ID').innerHTML;"
   return changeValue
  end tell
end tell

      

I get the result:

<option value=\"1\">blabla1</option>
<option selected=\"\" value=\"2\">blabla2</option>
<option value=\"3\">blabla3</option>

      

Now I want to change the selected option as value1.

Can someone please help me. I am very upset that nothing is working.

thank

Martin

+3


source to share


1 answer


You need to execute javascript to change the value of the select element. You must set it to the "value" parameter string in one of the choices.



tell application "Safari"
    activate
    tell current tab of window 1
        do JavaScript "document.getElementById('selected-ID').value = '1';"
    end tell
end tell

      

+1


source







All Articles