Description:
Class for iterating over elements of common type like links, images, divs etc.
# 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
# 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
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
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
Returns the first element in the collection.
# File lib/firewatir/element_collections.rb, line 164 def first @element_objects.first end
# 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
Returns the last element in the collection.
# File lib/firewatir/element_collections.rb, line 172 def last @element_objects.last end
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
default implementation. overridden by some subclasses.
# File lib/firewatir/element_collections.rb, line 37 def locate_elements locate_tagged_elements(element_class::TAG) end
# File lib/firewatir/element_collections.rb, line 176 def to_s map { |e| e.to_s }.join("\n") end