class WWW::Mechanize::Form
def set_fields(fields = {})
could do the following:
is zero based. For example, to set the second field named 'foo', you
the key as the index in to the form. The index
set the value of a duplicate field, use a value which is a Hash with
same name, this method will set the first one found. If you want to
name, value pairs. If there is more than one field found with the
This method sets multiple fields on the form. It takes a list of field
def set_fields(fields = {}) fields.each do |k,v| case v when Hash v.each do |index, value| self.fields_with(:name => k.to_s).[](index).value = value end else value = nil index = 0 [v].flatten.each do |val| index = val.to_i unless value.nil? value = val if value.nil? end self.fields_with(:name => k.to_s).[](index).value = value end end end