Extract LabelLocator
This commit is contained in:
parent
f6a9bed41e
commit
4ae94af45c
|
@ -99,10 +99,9 @@ module Webrat
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_field_id_for_label(label_text) #:nodoc:
|
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 = LabelLocator.new(self, label_text).locate)
|
||||||
if label
|
|
||||||
label.for_id
|
label.for_id
|
||||||
else
|
else
|
||||||
raise NotFoundError.new("Could not find the label with text #{label_text}")
|
raise NotFoundError.new("Could not find the label with text #{label_text}")
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue