Class: Watir::ElementCollection
- Inherits:
-
Object
- Object
- Watir::ElementCollection
- Includes:
- Enumerable
- Defined in:
- lib/watir-webdriver/element_collection.rb
Overview
Base class for element collections.
Direct Known Subclasses
AnchorCollection, AppletCollection, AreaCollection, AudioCollection, BRCollection, BaseCollection, BaseFontCollection, BodyCollection, ButtonCollection, CanvasCollection, CommandCollection, DListCollection, DataCollection, DataListCollection, DetailsCollection, DialogCollection, DirectoryCollection, DivCollection, EmbedCollection, FieldSetCollection, FontCollection, FormCollection, FrameCollection, FrameSetCollection, HRCollection, HTMLElementCollection, HeadCollection, HeadingCollection, HtmlCollection, IFrameCollection, ImageCollection, InputCollection, KeygenCollection, LICollection, LabelCollection, LegendCollection, MapCollection, MarqueeCollection, MediaCollection, MenuCollection, MetaCollection, MeterCollection, ModCollection, OListCollection, ObjectCollection, OptGroupCollection, OptionCollection, OutputCollection, ParagraphCollection, ParamCollection, PreCollection, ProgressCollection, QuoteCollection, ScriptCollection, SelectCollection, SourceCollection, SpanCollection, StyleCollection, TableCaptionCollection, TableCellCollection, TableColCollection, TableCollection, TableDataCellCollection, TableHeaderCellCollection, TableRowCollection, TableSectionCollection, TextAreaCollection, TimeCollection, TitleCollection, TrackCollection, UListCollection, UnknownCollection, VideoCollection
Instance Method Summary (collapse)
-
- (Watir::Element) [](idx)
Get the element at the given index.
-
- (Object) each {|element| ... }
Yields each element in collection.
-
- (Watir::Element) first
First element of this collection.
-
- (ElementCollection) initialize(parent, selector)
constructor
A new instance of ElementCollection.
-
- (Watir::Element) last
Last element of the collection.
-
- (Fixnum) length
(also: #size)
Returns number of elements in collection.
-
- (Array<Watir::Element>) to_a
This collection as an Array.
Constructor Details
- (ElementCollection) initialize(parent, selector)
A new instance of ElementCollection
11 12 13 14 |
# File 'lib/watir-webdriver/element_collection.rb', line 11 def initialize(parent, selector) @parent = parent @selector = selector end |
Instance Method Details
- (Watir::Element) [](idx)
Get the element at the given index. Note that this is 0-indexed and not compatible with older Watir implementations.
Also note that because of Watir's lazy loading, this will return an Element instance even if the index is out of bounds.
54 55 56 |
# File 'lib/watir-webdriver/element_collection.rb', line 54 def [](idx) to_a[idx] || element_class.new(@parent, :index => idx) end |
- (Object) each {|element| ... }
Yields each element in collection.
28 29 30 |
# File 'lib/watir-webdriver/element_collection.rb', line 28 def each(&blk) to_a.each(&blk) end |
- (Watir::Element) first
First element of this collection
64 65 66 |
# File 'lib/watir-webdriver/element_collection.rb', line 64 def first self[0] end |
- (Watir::Element) last
Last element of the collection
74 75 76 |
# File 'lib/watir-webdriver/element_collection.rb', line 74 def last self[-1] end |
- (Fixnum) length Also known as: size
Returns number of elements in collection.
38 39 40 |
# File 'lib/watir-webdriver/element_collection.rb', line 38 def length elements.length end |
- (Array<Watir::Element>) to_a
This collection as an Array.
84 85 86 87 |
# File 'lib/watir-webdriver/element_collection.rb', line 84 def to_a # TODO: optimize - lazy element_class instance? @to_a ||= elements.map { |e| element_class.new(@parent, :element => e) } end |