Class: Webrat::Locators::FieldLabeledLocator
- Inherits:
-
Locator
show all
- Defined in:
- lib/webrat/core/locators/field_labeled_locator.rb
Overview
Instance Method Summary
collapse
Methods inherited from Locator
#initialize, #locate!
Instance Method Details
#error_message ⇒ Object
31
32
33
|
# File 'lib/webrat/core/locators/field_labeled_locator.rb', line 31
def error_message
"Could not find field labeled #{@value.inspect}"
end
|
9
10
11
|
# File 'lib/webrat/core/locators/field_labeled_locator.rb', line 9
def locate
matching_labels.any? && matching_labels.detect_mapped { |label| label.field }
end
|
#matching_label_elements ⇒ Object
21
22
23
24
25
|
# File 'lib/webrat/core/locators/field_labeled_locator.rb', line 21
def matching_label_elements
label_elements.select do |label_element|
text(label_element) =~ /^\W*#{Regexp.escape(@value.to_s)}\b/i
end
end
|
#matching_labels ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/webrat/core/locators/field_labeled_locator.rb', line 13
def matching_labels
matching_label_elements.sort_by do |label_element|
text(label_element).length
end.map do |label_element|
Label.load(@session, label_element)
end
end
|
#text(element) ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/webrat/core/locators/field_labeled_locator.rb', line 35
def text(element)
str = Webrat::XML.all_inner_text(element)
str.gsub!("\n","")
str.strip!
str.squeeze!(" ")
str
end
|