class FireWatir::ElementCollections

Description:

Class for iterating over elements of common type like links, images, divs etc.

Public Class Methods

inherited(subclass) click to toggle source
# File lib/firewatir/element_collections.rb, line 11
def self.inherited subclass
  class_name = Watir::Util.demodulize(subclass.to_s)
  method_name = Watir::Util.underscore(class_name)
  element_class_name = Watir::Util.singularize(class_name)

  FireWatir::Container.module_eval "def #{method_name}
  locate if respond_to?(:locate)
  return #{class_name}.new(self); end"

  subclass.class_eval "def element_class; #{element_class_name}; end"
end
new(container) click to toggle source
# File lib/firewatir/element_collections.rb, line 25
def initialize(container)
  @container = container
  elements = locate_elements
  length = elements.length
  #puts "length is : #{length}"

  @element_objects = Array.new(length)
  for i in 0..length - 1 do
    @element_objects[i] = element_class.new(container, :jssh_name, elements[i])
  end
end

Public Instance Methods

[](n) click to toggle source

Description:

Accesses nth element of same tag and type found on the page.

Input:

n - index of element (1 based)
# File lib/firewatir/element_collections.rb, line 156
def [](n)
  return @element_objects[n-1]
end
each() { |element_objects| ... } click to toggle source

Description:

Iterate over the elements of same tag and type found on the page.
# File lib/firewatir/element_collections.rb, line 143
def each
  for i in 0..@element_objects.length - 1
    yield @element_objects[i]
  end
end
first() click to toggle source

Returns the first element in the collection.

# File lib/firewatir/element_collections.rb, line 164
def first
  @element_objects.first
end
inspect() click to toggle source
# File lib/firewatir/element_collections.rb, line 180
def inspect
  '#<%s:0x%x length=%s container=%s> elements=%s>' %
    [self.class, hash*2, length.inspect, @container.inspect, @element_objects.inspect]
end
last() click to toggle source

Returns the last element in the collection.

# File lib/firewatir/element_collections.rb, line 172
def last
  @element_objects.last
end
length() click to toggle source

Description:

Gets the length of elements of same tag and type found on the page.

Ouput:

Count of elements found on the page.
# File lib/firewatir/element_collections.rb, line 134
def length
  return @element_objects.length
end
Also aliased as: size
locate_elements() click to toggle source

default implementation. overridden by some subclasses.

# File lib/firewatir/element_collections.rb, line 37
def locate_elements
  locate_tagged_elements(element_class::TAG)
end
size() click to toggle source
Alias for: length
to_s() click to toggle source
# File lib/firewatir/element_collections.rb, line 176
def to_s
  map { |e| e.to_s }.join("\n")
end