lib/mechanize/form.rb in mechanize-0.6.7 vs lib/mechanize/form.rb in mechanize-0.6.8
- old
+ new
@@ -30,15 +30,14 @@
alias :elements :fields
def initialize(form_node, elements_node)
@form_node, @elements_node = form_node, elements_node
- @form_node.attributes ||= {}
- @method = (@form_node.attributes['method'] || 'GET').upcase
- @action = Util::html_unescape(@form_node.attributes['action'])
- @name = @form_node.attributes['name']
- @enctype = @form_node.attributes['enctype'] || 'application/x-www-form-urlencoded'
+ @method = (@form_node['method'] || 'GET').upcase
+ @action = Util::html_unescape(@form_node['action'])
+ @name = @form_node['name']
+ @enctype = @form_node['enctype'] || 'application/x-www-form-urlencoded'
@clicked_buttons = []
parse
end
@@ -120,46 +119,43 @@
@radiobuttons = WWW::Mechanize::List.new
@checkboxes = WWW::Mechanize::List.new
# Find all input tags
(@elements_node/'input').each do |node|
- node.attributes ||= {}
- type = (node.attributes['type'] || 'text').downcase
- name = node.attributes['name']
+ type = (node['type'] || 'text').downcase
+ name = node['name']
next if name.nil? && !(type == 'submit' || type =='button')
case type
when 'text', 'password', 'hidden', 'int'
- @fields << Field.new(node.attributes['name'], node.attributes['value'] || '')
+ @fields << Field.new(node['name'], node['value'] || '')
when 'radio'
- @radiobuttons << RadioButton.new(node.attributes['name'], node.attributes['value'], node.attributes.has_key?('checked'), self)
+ @radiobuttons << RadioButton.new(node['name'], node['value'], node.has_attribute?('checked'), self)
when 'checkbox'
- @checkboxes << CheckBox.new(node.attributes['name'], node.attributes['value'], node.attributes.has_key?('checked'), self)
+ @checkboxes << CheckBox.new(node['name'], node['value'], node.has_attribute?('checked'), self)
when 'file'
- @file_uploads << FileUpload.new(node.attributes['name'], nil)
+ @file_uploads << FileUpload.new(node['name'], nil)
when 'submit'
- @buttons << Button.new(node.attributes['name'], node.attributes['value'])
+ @buttons << Button.new(node['name'], node['value'])
when 'button'
- @buttons << Button.new(node.attributes['name'], node.attributes['value'])
+ @buttons << Button.new(node['name'], node['value'])
when 'image'
- @buttons << ImageButton.new(node.attributes['name'], node.attributes['value'])
+ @buttons << ImageButton.new(node['name'], node['value'])
end
end
# Find all textarea tags
(@elements_node/'textarea').each do |node|
- next if node.attributes.nil?
- next if node.attributes['name'].nil?
- @fields << Field.new(node.attributes['name'], node.inner_text)
+ next if node['name'].nil?
+ @fields << Field.new(node['name'], node.inner_text)
end
# Find all select tags
(@elements_node/'select').each do |node|
- next if node.attributes.nil?
- next if node.attributes['name'].nil?
- if node.attributes.has_key? 'multiple'
- @fields << MultiSelectList.new(node.attributes['name'], node)
+ next if node['name'].nil?
+ if node.has_attribute? 'multiple'
+ @fields << MultiSelectList.new(node['name'], node)
else
- @fields << SelectList.new(node.attributes['name'], node)
+ @fields << SelectList.new(node['name'], node)
end
end
end
def rand_string(len = 10)