Working on FieldLabeled locator
This commit is contained in:
parent
27626ea389
commit
53979cbb52
@ -63,18 +63,6 @@ module Webrat
|
||||
possible_fields.detect { |possible_field| possible_field.matches_name?(name) }
|
||||
end
|
||||
|
||||
def field_labeled(label, *field_types)
|
||||
possible_fields = fields_by_type(field_types)
|
||||
matching_fields = possible_fields.select do |possible_field|
|
||||
possible_field.matches_label?(label)
|
||||
end
|
||||
matching_fields.min { |a, b| a.label_text.length <=> b.label_text.length }
|
||||
end
|
||||
|
||||
def label_matching(label_text)
|
||||
labels.detect { |label| label.matches_text?(label_text) }
|
||||
end
|
||||
|
||||
def matches_id?(id)
|
||||
Webrat::XML.attribute(@element, "id") == id.to_s
|
||||
end
|
||||
|
@ -1,6 +1,8 @@
|
||||
module Webrat
|
||||
class Label #:nodoc:
|
||||
|
||||
attr_reader :element
|
||||
|
||||
def self.xpath_search
|
||||
".//label"
|
||||
end
|
||||
@ -10,10 +12,6 @@ module Webrat
|
||||
@element = element
|
||||
end
|
||||
|
||||
def matches_text?(label_text)
|
||||
text =~ /^\W*#{Regexp.escape(label_text.to_s)}\b/i
|
||||
end
|
||||
|
||||
def text
|
||||
str = Webrat::XML.all_inner_text(@element)
|
||||
str.gsub!("\n","")
|
||||
|
@ -9,7 +9,15 @@ module Webrat
|
||||
def locate
|
||||
# TODO - Convert to using elements
|
||||
@scope.send(:forms).detect_mapped do |form|
|
||||
form.field_labeled(@value, *@field_types)
|
||||
possible_fields = form.send(:fields_by_type, @field_types)
|
||||
|
||||
matching_fields = possible_fields.select do |possible_field|
|
||||
possible_field.send(:labels).any? do |label|
|
||||
text(label) =~ /^\W*#{Regexp.escape(@value.to_s)}\b/i
|
||||
end
|
||||
end
|
||||
|
||||
matching_fields.min { |a, b| a.label_text.length <=> b.label_text.length }
|
||||
end
|
||||
end
|
||||
|
||||
@ -17,6 +25,14 @@ module Webrat
|
||||
"Could not find field labeled #{@value.inspect}"
|
||||
end
|
||||
|
||||
def text(label)
|
||||
str = Webrat::XML.all_inner_text(label.element)
|
||||
str.gsub!("\n","")
|
||||
str.strip!
|
||||
str.squeeze!(" ")
|
||||
str
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def field_labeled(label, *field_types)
|
||||
|
Loading…
Reference in New Issue
Block a user