Hi Bret Sorry I missed the wrapper code that i have written
require 'watir' include Watir include SupportsSubElements module SupportsSubElements def _getNikiraLink(links, how, what) link = nil case how when :index begin link = links[ (what-1).to_s ] rescue link=nil end when :url links.each do |thisLink| if what.matches(thisLink.href) link = thisLink if link == nil end end when :text links.each do |thisLink| if what.matches(thisLink.innerText.strip) link = thisLink if link == nil end end when :id links.each do |thisLink| if what.matches(thisLink.invoke("id")) link = thisLink if link == nil end end when :name links.each do |thisLink| if what.matches(thisLink.invoke("name")) link = thisLink if link == nil end end when :title links.each do |thisLink| if what.matches(thisLink.invoke("title")) link = thisLink if link == nil end end when :beforeText links.each do |thisLink| if what.matches(thisLink.getAdjacentText ("afterEnd").strip) link = thisLink if link == nil end end when :afterText links.each do |thisLink| if what.matches(thisLink.getAdjacentText ("beforeBegin").strip) link = thisLink if link == nil end end else raise MissingWayOfFindingObjectException, "#{how.inspect} is an unknown way of finding a link ( #{what} )" end return link end def getLink( how, what ) links = Array.new links = document.all.tags("A") # Guard ensures watir won't crash if somehow the list of links is nil if (links == nil) raise UnknownObjectException, "Unknown Object in getLink: attempted to click a link when no links present" end link = _getNikiraLink(links, how, what) # Guard ensures watir won't crash if somehow the list of links is nil if (link == nil) links = document.frames ['ifr_content'].document.all.tags("A") if (links == nil) raise UnknownObjectException, "Unknown Object in getLink: attempted to click a link when no links present" end link = _getNikiraLink(links, how, what) if (link == nil) raise UnknownObjectException.new("Unable to locate object, using #{how} and #{what} inside getLink") end end # if no link found, link will be a nil. This is OK. Actions taken on links (e.g. "click") should rescue # the nil-related exceptions and provide useful information to the user. return link end end class Watir::SpanDivCommon < Watir::Element def initialize( ieController, how , what ) @ieController = ieController @how = how @what = what @o = @ieController.getNonControlObject(tag , @how, @what ) unless @o @o = @ieController.getContainer.getNonControlObject(tag , @how, @what ) end super( @o ) @typingspeed = @ieController.typingspeed @activeObjectHighLightColor = @ ieController.activeObjectHighLightColor end end class Watir::Link < Watir::Element # Returns an initialized instance of a link object # * ieController - an instance of an IEController # * how - symbol - how we access the link # * what - what we use to access the link, text, url, index etc def initialize( ieController, how , what ) @ieController = ieController @how = how @what = what begin @o = @ieController.getLink( @how, @what ) rescue begin @o = @ieController.getContainer.getLink( @how, @what ) rescue @o = nil end end super( @o ) end end class Watir::Label < Watir::Element def initialize( ieController , how, what) @ieController = ieController @how = how @what = what @o = @ieController.getNonControlObject("LABEL" , @how, @what ) unless @o @o = @ieController.getContainer.getNonControlObject("LABEL" , @how, @what ) end super( @o ) end end class Watir::Table < Watir::Element def get_table allTables = @ieController.document.getElementsByTagName ("TABLE") @ieController.log "There are #{ allTables.length } tables" tableIndex = 1 table=nil allTables.each do |t| next unless table == nil case @how when :id if @what.matches( t.invoke("id").to_s ) table = t end when :index if tableIndex == @what.to_i table = t end end tableIndex = tableIndex + 1 end unless table allTables = @ ieController.getContainer.document.getElementsByTagName("TABLE") tableIndex = 1 table=nil allTables.each do |t| next unless table == nil case @how when :id if @what.matches( t.invoke("id").to_s ) table = t end when :index if tableIndex == @what.to_i table = t end end tableIndex = tableIndex + 1 end end return table end end class Watir::TableRow < Watir::Element def initialize(ieController , how, what) @ieController = ieController @how = how @what = what @o=nil if how == :direct @o = what else @o = ieController.getTablePart( "TR" , how , what ) end unless @o @o = ieController.getContainer.getTablePart( "TR" , how , what ) end update_row_cells super( @o ) end end class Watir::Button < Watir::Element def initialize( ieController, how , what ) @ieController = ieController @how = how @what = what if(how == :from_object) then @o = what else @o = @ieController.getContainer.getObject( @how, @what , object_types) end unless @o @o = @ieController.getObject( @how, @what , object_types) end super( @o ) end def object_types return ["button" , "submit" , "image" , "reset" ] end end class Watir::TableCell < Watir::Element def initialize( ieController, how , what ) @ieController = ieController #puts "How = #{how}" if how == :direct @o = what #puts "@[EMAIL PROTECTED]" else @o = ieController.getTablePart( "TD" , how , what ) end unless @o @o = ieController.getContainer.getTablePart( "TD" , how , what ) end super( @o ) @how = how @what = what @typingspeed = @ieController.typingspeed @activeObjectHighLightColor = @ ieController.activeObjectHighLightColor end end class Watir::Image < Watir::Element def initialize( ieController, how , what ) @ieController = ieController @how = how @what = what @o = @ieController.getImage(@how, @what) unless @o @o = @ieController.getContainer.getImage(@how, @what) end super( @o ) end end class Watir::SelectList < Watir::Element def initialize( ieController, how , what ) @ieController = ieController @how = how @what = what @o = @ieController.getContainer.getObject(@how, @what, ["select-one", "select-multiple"]) unless @o @o = @ieController.getObject(@how, @what, ["select-one", "select-multiple"]) end super( @o ) end end class Watir::RadioCheckCommon < Watir::Element def initialize( ieController, how , what , type, value=nil ) @ieController = ieController @how = how @what = what @type = type @value = value @o = @ieController.getContainer.getObject(@how, @what, @type, @value) unless @o @o = @ieController.getObject(@how, @what, @type, @value) end super( @o ) end end class Watir::TextField < Watir::Element def initialize( ieController, how , what ) @ieController = ieController @how = how @what = what if(how != :from_object) then @o = @ieController.getContainer.getObject(@how, @what, supported_types) else @o = what end unless @o @o = @ieController.getObject(@how, @what, supported_types) end super( @o ) end end class Watir::Frame < Watir::IE def initialize(container, how, what) @container = container @frame = nil frames = @container.document.frames for i in 0 .. frames.length-1 next unless @frame == nil this_frame = frames.item(i) if how == :index if i+1 == what @frame = this_frame end elsif how == :name begin if what.matches(this_frame.name) @frame = this_frame end rescue # access denied? end elsif how == :id # BUG: Won't work for IFRAMES if what.matches(@container.document.getElementsByTagName ("FRAME").item(i).invoke("id")) @frame = this_frame end else raise ArgumentError, "Argument #{how} not supported" end end unless @frame frames = @container.getContainer.document.frames for i in 0 .. frames.length-1 next unless @frame == nil this_frame = frames.item(i) if how == :index if i+1 == what @frame = this_frame end elsif how == :name begin if what.matches(this_frame.name) @frame = this_frame end rescue # access denied? end elsif how == :id # BUG: Won't work for IFRAMES if what.matches(@container.document.getElementsByTagName ("FRAME").item(i).invoke("id")) @frame = this_frame end else raise ArgumentError, "Argument #{how} not supported" end end unless @frame raise UnknownFrameException , "Unable to locate a frame with name #{ what} " end end @typingspeed = container.typingspeed @activeObjectHighLightColor = container.activeObjectHighLightColor end def ie return @frame end def document @frame.document end def wait(no_sleep = false) @container.wait(no_sleep) end # IE methods def refresh @container.refresh end def close @container.close end def getContainer return @container end def dir return Watir::IE.new.dir end def contains_text(text) return @container.contains_text(text) end end
_______________________________________________ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general