【问题标题】:set value for selectlist in Mechanize在机械化中为选择列表设置值
【发布时间】: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


    【解决方案1】:

    试试吧:

    result_form.scode = 'foo'
    

    【讨论】:

    • 这么简单!不确定,为什么我不早点尝试:D
    【解决方案2】:

    result_form["scode"] = "foo" 应该可以解决问题。 Reference in the docs

    【讨论】:

      猜你喜欢
      • 2012-04-10
      • 1970-01-01
      • 1970-01-01
      • 2012-05-16
      • 2011-04-02
      • 2015-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多