mechanize:Mechanize::Form#checkbox_with, #checkbox
以下のような HTML で
<html> <head> <title>form test</title> </head> <body> <form method="get" action="cgi/foo00.cgi" name="form1"> <input type="checkbox" name="checkbox1" value="foo" />Foo <input type="checkbox" name="checkbox1" value="bar" />Bar <input type="checkbox" name="checkbox1" value="baz" />Baz </form> </body> </html>
>> require 'mechanize' => true >> agent = Mechanize.new => #<Mechanize:0xb74745ac ... >> page = agent.get('http://127.0.0.1:8080/test14_checkbox.html') => #<Mechanize::Page {url #<URI::HTTP:0xb7470b64 URL:http://127.0.0.1:8080/test14_checkbox.html>} {meta} {title "form test"} {iframes} {frames} {links} {forms #<Mechanize::Form {name "form1"} {method "GET"} {action "cgi/foo00.cgi"} {fields} {radiobuttons} {checkboxes #<Mechanize::Form::CheckBox:0xb7468194 @checked=false, @name="checkbox1", @value="foo"> #<Mechanize::Form::CheckBox:0xb746802c @checked=false, @name="checkbox1", @value="bar"> #<Mechanize::Form::CheckBox:0xb7467ec4 @checked=false, @name="checkbox1", @value="baz">} {file_uploads} {buttons}>}> >> f = page.form('form1') => #<Mechanize::Form {name "form1"} {method "GET"} {action "cgi/foo00.cgi"} {fields} {radiobuttons} {checkboxes #<Mechanize::Form::CheckBox:0xb7468194 @checked=false, @name="checkbox1", @value="foo"> #<Mechanize::Form::CheckBox:0xb746802c @checked=false, @name="checkbox1", @value="bar"> #<Mechanize::Form::CheckBox:0xb7467ec4 @checked=false, @name="checkbox1", @value="baz">} {file_uploads} {buttons}> >> f.checkbox_with(:name => /checkbox/) => #<Mechanize::Form::CheckBox:0xb7468194 @checked=false, @name="checkbox1", @value="foo", @form=#<Mechanize::Form {name "form1"} {method "GET"} {action "cgi/foo00.cgi"} {fields} {radiobuttons} {checkboxes #<Mechanize::Form::CheckBox:0xb7468194 @checked=false, @name="checkbox1", @value="foo"> #<Mechanize::Form::CheckBox:0xb746802c @checked=false, @name="checkbox1", @value="bar"> #<Mechanize::Form::CheckBox:0xb7467ec4 @checked=false, @name="checkbox1", @value="baz">} {file_uploads} {buttons}> , @node=#<Nokogiri::XML::Element:0x..fdba34142 name="input" attributes=[#<Nokogiri::XML::Attr:0x..fdba2b452 name="type" value="checkbox">, #<Nokogiri::XML::Attr:0x..fdba2b448 name="name" value="checkbox1">, #<Nokogiri::XML::Attr:0x..fdba2b43e name="value" value="foo">]>> >> f.checkbox(:name => /checkbox/) => #<Mechanize::Form::CheckBox:0xb7468194 @checked=false, @name="checkbox1", @value="foo", @form=#<Mechanize::Form {name "form1"} {method "GET"} {action "cgi/foo00.cgi"} {fields} {radiobuttons} {checkboxes #<Mechanize::Form::CheckBox:0xb7468194 @checked=false, @name="checkbox1", @value="foo"> #<Mechanize::Form::CheckBox:0xb746802c @checked=false, @name="checkbox1", @value="bar"> #<Mechanize::Form::CheckBox:0xb7467ec4 @checked=false, @name="checkbox1", @value="baz">} {file_uploads} {buttons}> , @node=#<Nokogiri::XML::Element:0x..fdba34142 name="input" attributes=[#<Nokogiri::XML::Attr:0x..fdba2b452 name="type" value="checkbox">, #<Nokogiri::XML::Attr:0x..fdba2b448 name="name" value="checkbox1">, #<Nokogiri::XML::Attr:0x..fdba2b43e name="value" value="foo">]>>