mechanize:Mechanize::Form::MultiSelectList#selected_options
以下のような HTML で
<html> <head> <title>form test</title> </head> <body> <form method="get" action="cgi/foo00.cgi" name="form1"> <select name="select1"> <option>1</option> <option>2</option> </select> <select name="select2" multiple> <option>foo</option> <option>bar</option> </select> </form> </body> </html>
>> require 'mechanize' => true >> agent = Mechanize.new => #<Mechanize:0xb74ab5ac ... >> page = agent.get('http://127.0.0.1:8080/test20_select.html') => #<Mechanize::Page ... >> f = page.form('form1') => #<Mechanize::Form ... >> f.fields[1].query_value => [] >> f.fields[1].selected_options => [] >> f.fields[1].value = 'foo' => "foo" >> f.fields[1].selected_options => [#<Mechanize::Form::Option:0xb749d934 @select_list=#<Mechanize::Form::MultiSelectList:0xb749dc04 @options=[#<Mechanize::Form::Option:0xb749d934 ...>, #<Mechanize::Form::Option:0xb749d880 @select_list=#<Mechanize::Form::MultiSelectList:0xb749dc04 ...>, @selected=false, @text="bar", @value="bar">], @name="select2", @value=[], @node=#<Nokogiri::XML::Element:0x..fdba4ee3e name="select" attributes=[#<Nokogiri::XML::Attr:0x..fdba4a276 name="name" value="select2">, #<Nokogiri::XML::Attr:0x..fdba4a26c name="multiple" value="multiple">] children=[#<Nokogiri::XML::Element:0x..fdba4ece0 name="option" children=[#<Nokogiri::XML::Text:0x..fdba4910a "foo">]>, #<Nokogiri::XML::Element:0x..fdba4ecae name="option" children=[#<Nokogiri::XML::Text:0x..fdba48980 "bar">]>]>>, @selected=true, @text="foo", @value="foo">] >> f.fields[1].value = 'bar' => "bar" >> f.fields[1].selected_options => [#<Mechanize::Form::Option:0xb749d880 @select_list=#<Mechanize::Form::MultiSelectList:0xb749dc04 @options=[#<Mechanize::Form::Option:0xb749d934 @select_list=#<Mechanize::Form::MultiSelectList:0xb749dc04 ...>, @selected=false, @text="foo", @value="foo">, #<Mechanize::Form::Option:0xb749d880 ...>], @name="select2", @value=[], @node=#<Nokogiri::XML::Element:0x..fdba4ee3e name="select" attributes=[#<Nokogiri::XML::Attr:0x..fdba4a276 name="name" value="select2">, #<Nokogiri::XML::Attr:0x..fdba4a26c name="multiple" value="multiple">] children=[#<Nokogiri::XML::Element:0x..fdba4ece0 name="option" children=[#<Nokogiri::XML::Text:0x..fdba4910a "foo">]>, #<Nokogiri::XML::Element:0x..fdba4ecae name="option" children=[#<Nokogiri::XML::Text:0x..fdba48980 "bar">]>]>>, @selected=true, @text="bar", @value="bar">] >> f.fields[1].value = ['foo', 'bar'] => ["foo", "bar"] >> f.fields[1].selected_options => [#<Mechanize::Form::Option:0xb749d934 @select_list=#<Mechanize::Form::MultiSelectList:0xb749dc04 @options=[#<Mechanize::Form::Option:0xb749d934 ...>, #<Mechanize::Form::Option:0xb749d880 @select_list=#<Mechanize::Form::MultiSelectList:0xb749dc04 ...>, @selected=true, @text="bar", @value="bar">], @name="select2", @value=[], @node=#<Nokogiri::XML::Element:0x..fdba4ee3e name="select" attributes=[#<Nokogiri::XML::Attr:0x..fdba4a276 name="name" value="select2">, #<Nokogiri::XML::Attr:0x..fdba4a26c name="multiple" value="multiple">] children=[#<Nokogiri::XML::Element:0x..fdba4ece0 name="option" children=[#<Nokogiri::XML::Text:0x..fdba4910a "foo">]>, #<Nokogiri::XML::Element:0x..fdba4ecae name="option" children=[#<Nokogiri::XML::Text:0x..fdba48980 "bar">]>]>>, @selected=true, @text="foo", @value="foo">, #<Mechanize::Form::Option:0xb749d880 @select_list=#<Mechanize::Form::MultiSelectList:0xb749dc04 @options=[#<Mechanize::Form::Option:0xb749d934 @select_list=#<Mechanize::Form::MultiSelectList:0xb749dc04 ...>, @selected=true, @text="foo", @value="foo">, #<Mechanize::Form::Option:0xb749d880 ...>], @name="select2", @value=[], @node=#<Nokogiri::XML::Element:0x..fdba4ee3e name="select" attributes=[#<Nokogiri::XML::Attr:0x..fdba4a276 name="name" value="select2">, #<Nokogiri::XML::Attr:0x..fdba4a26c name="multiple" value="multiple">] children=[#<Nokogiri::XML::Element:0x..fdba4ece0 name="option" children=[#<Nokogiri::XML::Text:0x..fdba4910a "foo">]>, #<Nokogiri::XML::Element:0x..fdba4ecae name="option" children=[#<Nokogiri::XML::Text:0x..fdba48980 "bar">]>]>>, @selected=true, @text="bar", @value="bar">]