Class: Watir::ElementCollections
- Inherits:
-
Object
- Object
- Watir::ElementCollections
show all
- Includes:
- Enumerable
- Defined in:
- lib/watir/element_collections.rb
Overview
this class is the super class for the iterator classes (buttons, links, spans etc it would normally only be accessed by the iterator methods (spans, links etc) of IE
Instance Method Summary
collapse
Constructor Details
Super class for all the iteractor classes
* container - an instance of an IE object
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/watir/element_collections.rb', line 9
def initialize(container, how, what)
if how == :index || (how.is_a?(Hash) && how[:index])
_how = what ? "#{how.inspect}, #{what.inspect}" : "#{how.inspect}"
raise Exception::MissingWayOfFindingObjectException,
"#{self.class} does not support attribute :index in #{_how}"
end
@container = container
@how = how
@what = what
@length = length
@page_container = container.page_container
end
|
Instance Method Details
#[](n) ⇒ Object
allows access to a specific item in the collection
37
38
39
40
41
42
43
|
# File 'lib/watir/element_collections.rb', line 37
def [](n)
unless n.between?(0, length - 1)
raise Exception::MissingWayOfFindingObjectException,
"Can't find #{element_tag.downcase} with :index #{n} from #{self.class} with size of #{length}"
end
return iterator_object(n)
end
|
#each ⇒ Object
iterate through each of the elements in the collection in turn
32
33
34
|
# File 'lib/watir/element_collections.rb', line 32
def each
@container.tagged_element_locator(element_tag, @how, @what, element_class).each {|element| yield element}
end
|
#first ⇒ Object
45
46
47
|
# File 'lib/watir/element_collections.rb', line 45
def first
iterator_object(0)
end
|
#inspect ⇒ Object
57
58
59
|
# File 'lib/watir/element_collections.rb', line 57
def inspect
'#<%s:0x%x length=%s container=%s>' % [self.class, hash*2, @length.inspect, @container.inspect]
end
|
#last ⇒ Object
49
50
51
|
# File 'lib/watir/element_collections.rb', line 49
def last
iterator_object(length - 1)
end
|
#length ⇒ Object
Also known as:
size
23
24
25
26
27
|
# File 'lib/watir/element_collections.rb', line 23
def length
count = 0
each {|element| count += 1 }
count
end
|
#to_s ⇒ Object
53
54
55
|
# File 'lib/watir/element_collections.rb', line 53
def to_s
map { |e| e.to_s }.join("\n")
end
|