[英]Javascript, how to select option when .selectedIndex is unknown
I am trying to use a combination of applescript and javascript to select and option from a dropdown select menu when the .selectedIndex is not known. 当.selectedIndex未知时,我尝试使用applescript和javascript的组合从下拉选择菜单中进行选择和选择。
tell application "Safari"
activate
tell document 1
do JavaScript "document.getElementsByName('dropdown')[0].selectedIndex=2"
end tell
end tell
This would select the 3rd option from a dropbdown menu (jelly) like this: 可以从下拉菜单(果冻)中选择第三个选项,如下所示:
<select name="dropdown">
<option value="shoe">shoe</option>
<option value="man">man</option>
<option value="jelly">jelly</option>
</select>
However my issue is that the dropdowns are always changing for example, I could go one day and it could look like this: 但是我的问题是,下拉列表总是在变化,例如,我可能有一天可能看起来像这样:
<select name="dropdown">
<option value="billy">billy</option>
<option value="shoe">shoe</option>
<option value="man">man</option>
<option value="jelly">jelly</option>
</select>
This time the 'man' option would be selected. 这次将选择“ man”选项。
Solution: 解:
set valuex to "jelly"
tell application "Safari"
activate
tell document 1
do JavaScript "document.getElementsByName('dropdown')[0].value='" & valuex & "';"
end tell
end tell
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.