【发布时间】:2012-07-03 12:24:51
【问题描述】:
考虑下面的机械化表单对象
#<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 methodclick' for nil:NilClass (NoMethodError)`
然后,我尝试了
result_form.scode.value = 'foo'
但这也会返回NoMethodError。知道如何在 Mechanize 中为选择列表设置值吗?
【问题讨论】:
标签: ruby mechanize mechanize-ruby