1

考虑以下机械化表单对象

#<Mechanize::Form
 {name "f1"}
 {method "POST"}
 {action "f.php"}
 {fields
  [hidden:0x4db4b02 type: hidden name: opflag value: ]
  [text:0x4db463e type: text name: lno value: 666]
  [selectlist:0x4db84dc type:  name: scode value: []]}
 {radiobuttons}
 {checkboxes}
 {file_uploads}
 {buttons [button:0x4db42ec type: button name: bt value:  Show Result ]}>

在这里,我可以使用设置文本字段的值

result_form = page.form('f1')
result_form.lno = '666'

但是我在为选择列表设置值时遇到了困难scode。我试过了

result_form.field_with(name:"scode").option_with(value: "foo").click

undefined method它为 nil:NilClass (NoMethodError)`返回一个 ERROR 作为 click' 然后,我尝试了

result_form.scode.value = 'foo'

但这NoMethodError也会返回。知道如何在 Mechanize 中为选择列表设置值吗?

4

2 回答 2

2

试试:

result_form.scode = 'foo'
于 2012-07-03T07:01:52.557 回答
1

result_form["scode"] = "foo"应该做的伎俩。文档中的参考

于 2012-07-03T07:23:32.167 回答