My current challenge involves using a mix of applescript and javascript to choose an option from a dropdown select menu without knowing the .selectedIndex in advance.
tell application "Safari"
activate
tell document 1
do JavaScript "document.getElementsByName('dropdown')[0].selectedIndex=2"
end tell
end tell
In this case, the code would select the 3rd option (jelly) from a dropdown menu structured like this:
<select name="dropdown">
<option value="shoe">shoe</option>
<option value="man">man</option>
<option value="jelly">jelly</option>
</select>
The issue arises when the dropdown options change constantly. For example, it could be updated to look like this on another day:
<select name="dropdown">
<option value="billy">billy</option>
<option value="shoe">shoe</option>
<option value="man">man</option>
<option value="jelly">jelly</option>
</select>
In this scenario, the 'man' option would now be selected instead.