Class: Watir::TaggedElementLocator
Constant Summary
Constants included
from Watir
ATTACHER
Instance Method Summary
collapse
Methods inherited from Locator
#normalize_specifiers!
Methods included from Watir
_register, _unregister, autoit, #dialog, until_with_timeout
Constructor Details
Returns a new instance of TaggedElementLocator.
27
28
29
30
|
# File 'lib/watir/locator.rb', line 27
def initialize(container, tag)
@container = container
@tag = tag
end
|
Instance Method Details
#each_element(tag) ⇒ Object
43
44
45
46
47
|
# File 'lib/watir/locator.rb', line 43
def each_element tag
@container.document.getElementsByTagName(tag).each do |ole_element|
yield Element.new(ole_element)
end
end
|
#locate ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/watir/locator.rb', line 49
def locate
count = 0
each_element(@tag) do |element|
catch :next_element do
@specifiers.each do |how, what|
next if how == :index
unless match? element, how, what
throw :next_element
end
end
count += 1
unless count == @specifiers[:index]
throw :next_element
end
return element.ole_object
end
end
nil
end
|
#match?(element, how, what) ⇒ Boolean
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/watir/locator.rb', line 71
def match?(element, how, what)
begin
method = element.method(how)
rescue NameError
raise MissingWayOfFindingObjectException,
"#{how} is an unknown way of finding a <#{@tag}> element (#{what})"
end
case method.arity
when 0
what.matches method.call
when 1
method.call(what)
else
raise MissingWayOfFindingObjectException,
"#{how} is an unknown way of finding a <#{@tag}> element (#{what})"
end
end
|
#set_specifier(how, what) ⇒ Object
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/watir/locator.rb', line 32
def set_specifier(how, what)
if how.class == Hash and what.nil?
specifiers = how
else
specifiers = {how => what}
end
@specifiers = {:index => 1}
normalize_specifiers! specifiers
end
|