Class: 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, DataListCollection, DetailsCollection, DeviceCollection, 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
- #[](idx) ⇒ Object
- #each {|element| ... } ⇒ Object
-
#first ⇒ Watir::Element
First element of this collection.
-
#initialize(parent, selector) ⇒ ElementCollection
constructor
A new instance of ElementCollection.
-
#last ⇒ Watir::Element
Last element of the collection.
-
#length ⇒ Fixnum
(also: #size)
The number of elements in this collection.
-
#to_a ⇒ Array<Watir::Element>
This collection as an Array.
Constructor Details
#initialize(parent, selector) ⇒ ElementCollection
Returns 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
#[](idx) ⇒ Object
45 46 47 |
# File 'lib/watir-webdriver/element_collection.rb', line 45 def [](idx) to_a[idx] || element_class.new(@parent, :index => idx) end |
#each {|element| ... } ⇒ Object
20 21 22 |
# File 'lib/watir-webdriver/element_collection.rb', line 20 def each(&blk) to_a.each(&blk) end |
#first ⇒ Watir::Element
First element of this collection
55 56 57 |
# File 'lib/watir-webdriver/element_collection.rb', line 55 def first self[0] end |
#last ⇒ Watir::Element
Last element of the collection
65 66 67 |
# File 'lib/watir-webdriver/element_collection.rb', line 65 def last self[-1] end |
#length ⇒ Fixnum Also known as: size
Returns The number of elements in this collection.
28 29 30 |
# File 'lib/watir-webdriver/element_collection.rb', line 28 def length elements.length end |
#to_a ⇒ Array<Watir::Element>
This collection as an Array
75 76 77 78 |
# File 'lib/watir-webdriver/element_collection.rb', line 75 def to_a # TODO: optimize - lazy element_class instance? @to_a ||= elements.map { |e| element_class.new(@parent, :element => e) } end |