如何使用ruby / mechanize在表单中选择下拉列表的值

时间:2012-10-06 00:33:52

标签: ruby mechanize

如何在此下拉列表中选择第二个选项?

<select name="size" onchange="...js...">
  <option value="OPTION_CHOOSE">Please Select an Option</option>                            
  <option value="123">ABC</option>
  <option value="456">DFG</option>
  <option value="789">HIJ</option>
</select>

红宝石

require 'rubygems'
require 'mechanize'

url = "http://...."
agent = Mechanize.new
page = agent.get(url)

form = agent.page.forms.first

*select drop down*

1 个答案:

答案 0 :(得分:5)

form.field_with(:name => 'size').options[1].click