diff --git a/lib/webrat/core/locators.rb b/lib/webrat/core/locators.rb index 834f3f3..0b52fa7 100644 --- a/lib/webrat/core/locators.rb +++ b/lib/webrat/core/locators.rb @@ -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}") diff --git a/lib/webrat/core/locators/label_locator.rb b/lib/webrat/core/locators/label_locator.rb new file mode 100644 index 0000000..24b0835 --- /dev/null +++ b/lib/webrat/core/locators/label_locator.rb @@ -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 \ No newline at end of file