From 20561b0c411c687cd755be381109937910fcda97 Mon Sep 17 00:00:00 2001 From: Gwyn Morfey Date: Tue, 29 Apr 2008 12:26:16 +0100 Subject: [PATCH] Also find buttons by caption, if no value has been specified. --- lib/webrat/field.rb | 4 ++++ lib/webrat/form.rb | 5 +++++ 2 files changed, 9 insertions(+) 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