1

Consider the following Mechanize form object

#<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 ]}>

Here, I am able to set value of text field using

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

But I am facing difficulty in setting value for scode selectlist. I have tried

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

it returns an ERROR as undefined methodclick' for nil:NilClass (NoMethodError)` then, I tried

result_form.scode.value = 'foo'

But this returns NoMethodError as well. Any idea how to set value for selectlist in Mechanize?

CuriousMind
  • 33,537
  • 28
  • 98
  • 137

2 Answers2

2

Try just:

result_form.scode = 'foo'
pguardiario
  • 53,827
  • 19
  • 119
  • 159
1

result_form["scode"] = "foo" should do the trick. Reference in the docs

Igbanam
  • 5,904
  • 5
  • 44
  • 68