使用Applescript从Javascript下拉菜单中选择选项 - 如何?

时间:2014-05-30 00:46:22

标签: javascript drop-down-menu applescript

像这样使用AppleScript

set settrimsize to "'7.440" x 9.690" (246mm x 189mm)'"
   tell application "Safari"
do JavaScript "document.forms['aspnetForm']['_ctl0:_ctl0:MainContent:MainContent:ctlBookTypeSelector:ddlTrimSize'].value = " & settrimsize in document 1
end tell

应该可以从此列表中选择一个选项

<tr id="trimSizeRow">

<td align="right" class="formLabelSmallRight">
    <label>Trim Size</label>
</td>
 <tr id="trimSizeRow">

<td align="right" class="formLabelSmallRight">
<label>Trim Size</label>
</td>
<td align="left" width="60%">
<select name="_ctl0:_ctl0:MainContent:MainContent:ctlBookTypeSelector:ddlTrimSize" id="_ctl0__ctl0_MainContent_MainContent_ctlBookTypeSelector_ddlTrimSize">
<option selected="selected" value=""></option>
<option value="4.370&quot; x 7.000&quot; (178mm x 111mm)">4.370&quot; x 7.000&quot; (178mm x 111mm)</option>
<option value="4.72&quot; x 7.48&quot; (190mm x 120mm) ">4.72&quot; x 7.48&quot; (190mm x 120mm) </option>
<option value="5.000&quot; x 7.000&quot; (178mm x 127mm)">5.000&quot; x 7.000&quot; (178mm x 127mm)</option>
<option value="5.000&quot; x 8.000&quot; (203mm x 127mm)">5.000&quot; x 8.000&quot; (203mm x 127mm)</option>
<option value="5.060&quot; x 7.810&quot; (198mm x 129mm)">5.060&quot; x 7.810&quot; (198mm x 129mm)</option>
<option value="5.250&quot; x 8.000&quot; (203mm x 133mm)">5.250&quot; x 8.000&quot; (203mm x 133mm)</option>
<option value="5.500&quot; x 8.500&quot; (216mm x 140mm)">5.500&quot; x 8.500&quot; (216mm x 140mm)</option>
<option value="5.830&quot; x 8.270&quot; (210mm x 148mm) A5">5.830&quot; x 8.270&quot; (210mm x 148mm) A5</option>
<option value="6.000&quot; x 9.000&quot; (229mm x 152mm)">6.000&quot; x 9.000&quot; (229mm x 152mm)</option>
<option value="6.140&quot; x 9.210&quot; (234mm x 156mm)">6.140&quot; x 9.210&quot; (234mm x 156mm)</option>
<option value="6.690&quot; x 9.610&quot; (244mm x 170mm)">6.690&quot; x 9.610&quot; (244mm x 170mm)</option>
<option value="7.000&quot; x 10.00&quot; (254mm x 178mm)">7.000&quot; x 10.00&quot; (254mm x 178mm)</option>
<option value="7.440&quot; x 9.690&quot; (246mm x 189mm)">7.440&quot; x 9.690&quot; (246mm x 189mm)</option>
<option value="7.500&quot; x 9.250&quot; (235mm x 191mm)">7.500&quot; x 9.250&quot; (235mm x 191mm)</option>
<option value="8.000&quot; x 10.00&quot; (254mm x 203mm)">8.000&quot; x 10.00&quot; (254mm x 203mm)</option>
<option value="8.000&quot; x 10.88&quot; (276mm x 203mm)">8.000&quot; x 10.88&quot; (276mm x 203mm)</option>
<option value="8.000&quot; x 8.000&quot; (203mm x 203mm)">8.000&quot; x 8.000&quot; (203mm x 203mm)</option>
<option value="8.250&quot; x 11.00&quot; (280mm x 210mm)">8.250&quot; x 11.00&quot; (280mm x 210mm)</option>
<option value="8.268&quot; x 11.693&quot; (297mm x 210mm) A4">8.268&quot; x 11.693&quot; (297mm x 210mm) A4</option>
<option value="8.500&quot; x 11.00&quot; (280mm x 216mm)">8.500&quot; x 11.00&quot; (280mm x 216mm)</option>
<option value="8.500&quot; x 8.500&quot; (216mm x 216mm)">8.500&quot; x 8.500&quot; (216mm x 216mm)</option>
<option value="8.500&quot; x 9.000&quot; (229mm x 216mm)">8.500&quot; x 9.000&quot; (229mm x 216mm)</option>

</select>
</td>
</tr>

..但它没有 - 我已经盯着它看了一会儿,有点找不到如何让它起作用 - 任何帮助都会让我非常感激。

谢谢!

1 个答案:

答案 0 :(得分:1)

尝试:

set settrimsize to "7.440\" x 9.690\" (246mm x 189mm)"

tell application "Safari"
    tell current tab of window 1
        do JavaScript "document.getElementById('_ctl0__ctl0_MainContent_MainContent_ctlBookTypeSelector_ddlTrimSize').value='" & settrimsize & "';"
    end tell
end tell