Class: Watir::ElementCollection
- Includes:
- Enumerable
- Defined in:
- lib/watir-classic/element_collection.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
Direct Known Subclasses
HTMLElementCollection, InputElementCollection, TableElementCollection
Instance Method Summary collapse
-
#[](n) ⇒ Object
allows access to a specific item in the collection.
-
#each ⇒ Object
iterate through each of the elements in the collection in turn.
- #first ⇒ Object
-
#initialize(container, specifiers) ⇒ ElementCollection
constructor
Super class for all the iterator classes * container - an instance of an IE object.
- #inspect ⇒ Object
- #last ⇒ Object
- #length ⇒ Object (also: #size)
- #to_s ⇒ Object
Constructor Details
#initialize(container, specifiers) ⇒ ElementCollection
Super class for all the iterator classes
* container - an instance of an IE object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/watir-classic/element_collection.rb', line 9 def initialize(container, specifiers) if specifiers[:index] raise Exception::MissingWayOfFindingObjectException, "#{self.class} does not support attribute :index in #{specifiers.inspect}" end @container = container @specifiers = specifiers @page_container = container.page_container end |
Instance Method Details
#[](n) ⇒ Object
allows access to a specific item in the collection
34 35 36 37 38 39 40 |
# File 'lib/watir-classic/element_collection.rb', line 34 def [](n) number = n - Watir::IE.base_index offset = Watir::IE.zero_based_indexing ? (length - 1) : length non_existing_element = element_class.new(@container, @specifiers.merge(:index => n)) def non_existing_element.locate; nil end iterator_object(number) || non_existing_element end |
#each ⇒ Object
iterate through each of the elements in the collection in turn
29 30 31 |
# File 'lib/watir-classic/element_collection.rb', line 29 def each @container.locator_for(TaggedElementLocator, @specifiers, element_class).each {|element| yield element} end |
#first ⇒ Object
42 43 44 |
# File 'lib/watir-classic/element_collection.rb', line 42 def first iterator_object(0) end |
#inspect ⇒ Object
54 55 56 |
# File 'lib/watir-classic/element_collection.rb', line 54 def inspect '#<%s:0x%x length=%s container=%s>' % [self.class, hash*2, length.inspect, @container.inspect] end |
#last ⇒ Object
46 47 48 |
# File 'lib/watir-classic/element_collection.rb', line 46 def last iterator_object(length - 1) end |
#length ⇒ Object Also known as: size
20 21 22 23 24 |
# File 'lib/watir-classic/element_collection.rb', line 20 def length count = 0 each {|element| count += 1 } count end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/watir-classic/element_collection.rb', line 50 def to_s map { |e| e.to_s }.join("\n") end |