Class: Webrat::Locators::LinkLocator
- Inherits:
-
Locator
show all
- Defined in:
- lib/webrat/core/locators/link_locator.rb
Overview
Instance Method Summary
collapse
Methods inherited from Locator
#initialize, #locate!
Instance Method Details
#error_message ⇒ Object
64
65
66
|
# File 'lib/webrat/core/locators/link_locator.rb', line 64
def error_message
"Could not find link with text, title, id or class #{@value.inspect}"
end
|
8
9
10
|
# File 'lib/webrat/core/locators/link_locator.rb', line 8
def locate
Link.load(@session, link_element)
end
|
#matches_class?(link) ⇒ Boolean
44
45
46
47
48
49
50
|
# File 'lib/webrat/core/locators/link_locator.rb', line 44
def matches_class?(link)
if @value.is_a?(Regexp)
(Webrat::XML.attribute(link, "class") =~ @value) ? true : false
else
Webrat::XML.attribute(link, "class").split(%r{\s}).include?(@value) unless Webrat::XML.attribute(link, "class").nil?
end
end
|
#matches_id?(link) ⇒ Boolean
36
37
38
39
40
41
42
|
# File 'lib/webrat/core/locators/link_locator.rb', line 36
def matches_id?(link)
if @value.is_a?(Regexp)
(Webrat::XML.attribute(link, "id") =~ @value) ? true : false
else
(Webrat::XML.attribute(link, "id") == @value) ? true : false
end
end
|
#matches_text?(link) ⇒ Boolean
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/webrat/core/locators/link_locator.rb', line 24
def matches_text?(link)
if @value.is_a?(Regexp)
matcher = @value
else
matcher = /#{Regexp.escape(@value.to_s)}/i
end
replace_nbsp(Webrat::XML.all_inner_text(link)) =~ matcher ||
replace_nbsp_ref(Webrat::XML.inner_html(link)) =~ matcher ||
Webrat::XML.attribute(link, "title")=~ matcher
end
|
#matching_links ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/webrat/core/locators/link_locator.rb', line 16
def matching_links
@matching_links ||= link_elements.select do |link_element|
matches_text?(link_element) ||
matches_id?(link_element) ||
matches_class?(link_element)
end
end
|
#replace_nbsp(str) ⇒ Object
56
57
58
|
# File 'lib/webrat/core/locators/link_locator.rb', line 56
def replace_nbsp(str)
str.gsub([0xA0].pack('U'), ' ')
end
|
#replace_nbsp_ref(str) ⇒ Object
60
61
62
|
# File 'lib/webrat/core/locators/link_locator.rb', line 60
def replace_nbsp_ref(str)
str.gsub(' ',' ').gsub(' ', ' ')
end
|