Checking a checkbox with Mechanize

1.4k views Asked by At

Once I managed to get the NOKOGIRI object I am interested in (in my case a checkbox), How do I "check" it ? I ve got the following

category.parent.children.children.check

that returns this array full of nokogiri objects :

 [#<Nokogiri::XML::Text:0x3fde5a78a26c "\r\n\t\t\t">, #<Nokogiri::XML::Element:0x3fde5a78a154 name="input" attributes=[#<Nokogiri::XML::Attr:0x3fde5a78a0a0 name="type" value="checkbox">, #<Nokogiri::XML::Attr:0x3fde5a78a064 name="name" value="epr_iid_selection[9]">, #<Nokogiri::XML::Attr:0x3fde5a78a014 name="value" value="652988">]>, #<Nokogiri::XML::Text:0x3fde4e0cd1b0 "\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t">, #<Nokogiri::XML::Text:0x3fde4e0cd0fc "Simple Messieurs Senior">, #<Nokogiri::XML::Text:0x3fde4e0ccfd0 "SM  ">, #<Nokogiri::XML::Text:0x3fde4e0cce2c "Senior">]

In this array I am only interested in the second element which is a checkbox I need to "check" :

#<Nokogiri::XML::Element:0x3fde55a0a028 name="input" attributes=[#<Nokogiri::XML::Attr:0x3fde5a751f70 name="type" value="checkbox">, #<Nokogiri::XML::Attr:0x3fde5a751f48 name="name" value="epr_iid_selection[9]">, #<Nokogiri::XML::Attr:0x3fde5a751ef8 name="value" value="652988">]>

How can I do that ?

1

There are 1 answers

0
deuxio On

Usually, you want to check boxes within a form.

form.checkbox_with(:name => 'box').check

For more information, here's the related doc: http://mechanize.rubyforge.org/GUIDE_rdoc.html

Hope this helps.