mechanize:Mechanize::Form#has_value?

以下のような HTML で

<html>
<head>
<title>form test</title>
</head>
<body>

<form method="get" action="cgi/foo00.cgi" name="form1">
  <input type="radio" name="radio1" value="foo" checked="checked" />Foo
  <input type="radio" name="radio1" value="bar" />Bar
</form>

</body>
</html>
>> require 'mechanize'
=> true
>> agent = Mechanize.new
=> #<Mechanize:0xb7458604 ...
>> page = agent.get('http://127.0.0.1:8080/test13_radiobutton.html')
=> #<Mechanize::Page
 {url
  #<URI::HTTP:0xb7454a90 URL:http://127.0.0.1:8080/test13_radiobutton.html>}
 {meta}
 {title "form test"}
 {iframes}
 {frames}
 {links}
 {forms
  #<Mechanize::Form
   {name "form1"}
   {method "GET"}
   {action "cgi/foo00.cgi"}
   {fields}
   {radiobuttons
    #<Mechanize::Form::RadioButton:0xb744c048
     @checked=true,
     @name="radio1",
     @value="foo">
    #<Mechanize::Form::RadioButton:0xb744bee0
     @checked=false,
     @name="radio1",
     @value="bar">}
   {checkboxes}
   {file_uploads}
   {buttons}>}>

>> f = page.form('form1')
=> #<Mechanize::Form
 {name "form1"}
 {method "GET"}
 {action "cgi/foo00.cgi"}
 {fields}
 {radiobuttons
  #<Mechanize::Form::RadioButton:0xb744c048
   @checked=true,
   @name="radio1",
   @value="foo">
  #<Mechanize::Form::RadioButton:0xb744bee0
   @checked=false,
   @name="radio1",
   @value="bar">}
 {checkboxes}
 {file_uploads}
 {buttons}>

>> f.has_value?("foo")
=> false
>> f.has_value?("bar")
=> false

フィールドしか対象でないようだ



以下のような HTML で

<html>
<head>
<title>form test</title>
</head>
<body>

<form method="get" action="cgi/foo00.cgi" name="form1">
  <input type="text" name="text1" />
  <input type="hidden" name="hidden1" />
  <textarea name="textarea1" rows="4" cols="40">foo</textarea>
</form>

</body>
</html>
>> require 'mechanize'
=> true
>> agent = Mechanize.new
=> #<Mechanize:0xb74155ac ...
>> page = agent.get('http://127.0.0.1:8080/test10_form.html')
=> #<Mechanize::Page
 {url #<URI::HTTP:0xb7411cf4 URL:http://127.0.0.1:8080/test10_form.html>}
  ...
>> f = page.form('form1')
=> #<Mechanize::Form
  ...

>> f.has_value?("")
=> true
>> f.has_value?("a")
=> false
>> f.field(:name => "text1")
=> #<Mechanize::Form::Text:0xb7409270 @name="text1", @value="", @node=#<Nokogiri::XML::Element:0x..fdba04a0a name="input" attributes=[#<Nokogiri::XML::Attr:0x..fdba03010 name="type" value="text">, #<Nokogiri::XML::Attr:0x..fdba03006 name="name" value="text1">]>>
>> f.field(:name => "text1").value = "a"
=> "a"
>> f.has_value?("a")
=> true