Extract LabelLocator

This commit is contained in:
Bryan Helmkamp 2008-11-29 13:20:18 -05:00
parent f6a9bed41e
commit 4ae94af45c
2 changed files with 21 additions and 3 deletions

View File

@ -99,10 +99,9 @@ module Webrat
end
def find_field_id_for_label(label_text) #:nodoc:
# TODO - Convert to using elements
require "webrat/core/locators/label_locator"
label = forms.detect_mapped { |form| form.label_matching(label_text) }
if label
if (label = LabelLocator.new(self, label_text).locate)
label.for_id
else
raise NotFoundError.new("Could not find the label with text #{label_text}")

View File

@ -0,0 +1,19 @@
require "webrat/core/locators/locator"
module Webrat
module Locators
class LabelLocator < Locator
def locate
# TODO - Convert to using elements
@scope.send(:forms).detect_mapped do |form|
form.label_matching(@value)
end
end
end
end
end