From 9e673539a5f8ed0f8aaec78dc8c5225612e8191e Mon Sep 17 00:00:00 2001 From: Gwyn Morfey Date: Mon, 7 Jul 2008 15:57:52 +0100 Subject: [PATCH] Now you can do clicks_button 'foo_123' (passing button ID, not value) --- lib/webrat/field.rb | 4 ++++ lib/webrat/form.rb | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/webrat/field.rb b/lib/webrat/field.rb index 5d13f7f..5dec37e 100644 --- a/lib/webrat/field.rb +++ b/lib/webrat/field.rb @@ -106,6 +106,10 @@ module Webrat @element["value"] =~ /^\W*#{Regexp.escape(value.to_s)}/i end + def matches_id?(id) + @element["id"] =~ /^\W*#{Regexp.escape(id.to_s)}/i + end + def matches_caption?(value) @element.innerHTML =~ /^\W*#{Regexp.escape(value.to_s)}/i end diff --git a/lib/webrat/form.rb b/lib/webrat/form.rb index 37d842d..2b81fc4 100644 --- a/lib/webrat/form.rb +++ b/lib/webrat/form.rb @@ -33,6 +33,10 @@ module Webrat possible_buttons = fields_by_type([ButtonField]) + possible_buttons.each do |possible_button| + return possible_button if possible_button.matches_id?(value) + end + possible_buttons.each do |possible_button| return possible_button if possible_button.matches_value?(value) end