SelectList with mechanism in Ruby

I am trying to set the value of a select list using Mechanize with Ruby. I can go to the page using a selection list, grab the form using the .form method and find the selection list.

report_form =page.form('form1') pp report_form.field_with(:name => "report_type") 

Returns the correct object correctly.

However, I still cannot set the value of this field! I tried:

 report_form.field_with(:name => "report_type").options.first.select report_form.field_with(:name => "report_type").options[1].select report_form.field_with(:name => "report_type").value = "Foo" 

But when I do then:

 pp report_form.field_with(:name => "report_type") 

The value field is left blank.

Is there something I am missing? Advice? Tricks? Better Mechanize Documents than Live at http://mechanize.rubyforge.org ?

Thanks!

Edit: Corresponding HTML: Corresponding HTML:

 <TD> <select id="report_type" name="report_type"> <option value="Foo1">Opt 1</option> <option value="Foo2">Opt 2</option> <option value="Foo3">Opt 3</option> </select></TD> 
+4
source share
5 answers

try it

 report_form.field_with(:name => "report_type").option_with(:value => "Foo").click # now report_form.field_With(:name => "report_type").value should bee "Foo" 

(through 1 , 2 )

+6
source

This is usually good enough:

 report_form["report_type"] = "Foo" 
+2
source

I ran into the same problem, nothing works for me, but id would like to clarify that they were able to set the value for anything but the selection options.

  report_form.field_with(:name => "report_type").value = "Foo1" report_form["report_type"] => "Foo1" report_form.field_with(:name => "report_type").value => "Foo1" report_form.field_with(:name => "report_type") => [selectlist:0x7c08ada type: name: "report_type" value: []] 

after submitting the form, the selection is considered empty, however, if I do

  report_form.field_with(:name => "report_type").value = "anything not in the options" report_form.field_with(:name => "report_type") => [selectlist:0x7c08ada type: name: "report_type" value: ["anything not in the options"]] 
+1
source

Foo is not on the selection list, I think if you change it to Foo1 (or others), it should work !?

0
source

In fact, this turned out to be a mistake in the Mechanize jewel. Make sure you are using v 0.6.0 or later.

0
source

Source: https://habr.com/ru/post/1403502/


All Articles