Index: watir.rb
===================================================================
RCS file: /var/cvs/wtr/watir/watir.rb,v
retrieving revision 1.268
diff -u -r1.268 watir.rb
--- watir.rb	28 Nov 2005 09:57:42 -0000	1.268
+++ watir.rb	29 Nov 2005 05:32:11 -0000
@@ -2236,37 +2236,63 @@
         def locate
             how = @how
             what = @what
-            frames = @container.document.frames
-            target = nil
-
-            for i in 0 .. (frames.length - 1)
-                next unless target == nil
-                this_frame = frames.item(i)
-                if how == :index 
-                    if i + 1 == what
-                        target = this_frame
-                    end
-                elsif how == :name
-                    begin
-                        if what.matches(this_frame.name)
-                            target = 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"))
-                        target = this_frame
-                    end
-                else
-                    raise ArgumentError, "Argument #{how} not supported"
-                end
-            end
+			
+			if( how == :index )
+			
+				# if we were passed :index, simply use .document.frames ( which includes both the "FRAME"s and the "IFRAME"s )
+				combined = @container.document.frames
+
+				# since watir is currently 1-based on the indexes, drop one and just return the given frame  ( be sure to check and make sure the user didn't ask off either end of the array. )
+				if ( what - 1 ) <= combined.frames.length and ( what > 0 )
+					target = combined.frames.item( what - 1 )
+				else
+					raise UnknownFrameException, "#{ what } is an invalid index for frames on the current page"
+				end
+				
+			else
+			
+				# we're not looking for an index so we'll have to search through all the frames and the iframes.... 
+			
+				# collect our sets of frames
+				frames = @container.document.getElementsByTagName( "FRAME" )
+				iframes = @container.document.getElementsByTagName( "IFRAME" )
+				
+				# collect those sets into one larger object.
+				frameset = [ frames, iframes ]
+				
+				target = nil
+				
+				# now iterate our collections...
+				frameset.each do |curr_frame_array|
+					# and iterate through each of the frames in each of those collections.
+					for i in 0 ... curr_frame_array.length
+					
+						# make sure we haven't already found something
+						next unless target == nil
+						
+						this_frame = curr_frame_array.item( i )
+						
+						# check for the 3 supported methods of finding a frame or iframe  ( :src, :name, :id ) ... these three are in addition to :index which is checked for above.
+						case how
+							when :src, :name, :id
+								begin
+									# pull these values directly from the ole object.
+									target == this_frame if what.matches this_frame.invoke( how.to_s )
+								rescue # access denied? unsupported property?
+								end
+							else
+								# we got something wierd for how, error out.
+								raise ArgumentError, "Argument #{ how } not supported"
+						end
+					end
+				end
+			end
             
-            unless target
-                raise UnknownFrameException, "Unable to locate a frame with name #{ what} " 
-            end
-            target        
+			# Ok, if target == nil, we didn't find what we were looking for.
+			raise UnknownFrameException, "Unable to locate a frame with #{ how } #{ what }" if target == nil
+
+			# we're done, if we got here, we've found a frame.
+			target        
         end
     
         def initialize(container, how, what)
