diff --git a/lib/webrat/field.rb b/lib/webrat/field.rb index ee99d26..5d13f7f 100644 --- a/lib/webrat/field.rb +++ b/lib/webrat/field.rb @@ -105,6 +105,10 @@ module Webrat def matches_value?(value) @element["value"] =~ /^\W*#{Regexp.escape(value.to_s)}/i end + + def matches_caption?(value) + @element.innerHTML =~ /^\W*#{Regexp.escape(value.to_s)}/i + end def to_param return nil if @value.nil? diff --git a/lib/webrat/form.rb b/lib/webrat/form.rb index 265b20c..37d842d 100644 --- a/lib/webrat/form.rb +++ b/lib/webrat/form.rb @@ -37,6 +37,11 @@ module Webrat return possible_button if possible_button.matches_value?(value) end + #If nothing matched on value, try by name. + possible_buttons.each do |possible_button| + return possible_button if possible_button.matches_caption?(value) + end + nil end