vendor/gems/gems/firewatir-1.2.1/MozillaBaseElement.rb
#
# Description:
#   Locates frame element. Logic for locating the frame is written in JavaScript so that we don't make small
#   round trips to JSSh using socket. This is done to improve the performance for locating the element.
#
# Input:
#   how - The attribute for locating the frame. You can use any attribute-value pair that uniquely identifies
#         the frame on the page. If there are more than one frames that have identical attribute-value pair
#         then first frame that is found while traversing the DOM will be returned.
#   what - Value of the attribute specified by how
#
# Output:
#   Nil if unable to locate frame, else return the Frame element.
#

Locates frame element. Logic for locating the frame is written in JavaScript so that we don't make small
round trips to JSSh using socket. This is done to improve the performance for locating the element.

The attribute for locating the frame. You can use any attribute-value pair that uniquely identifies
the frame on the page. If there are more than one frames that have identical attribute-value pair
then first frame that is found while traversing the DOM will be returned.
what - Value of the attribute specified by how

Nil if unable to locate frame, else return the Frame element.
Locates frame element . Logic for locating the frame is written in JavaScript so that we don ' t make small round trips to JSSh using socket . This is done to improve the performance for locating the element . The attribute for locating the frame . You can use any attribute - value pair that uniquely identifies the frame on the page . If there are more than one frames that have identical attribute - value pair then first frame that is found while traversing the DOM will be returned . what - Value of the attribute specified by how Nil if unable to locate frame else return the Frame element .
def locate_frame(how, what)
            jssh_command = ""
            if(@container.class == FireWatir::Firefox)
                jssh_command = "var frameset = #{WINDOW_VAR}.frames;
                                var elements_frames = new Array();
                                for(var i = 0; i < frameset.length; i++)
                                {
                                    var frames = frameset[i].frames;
                                    for(var j = 0; j < frames.length; j++)
                                    {
                                        frames[j].frameElement.toString = function() { return '[object HTMLFrameElement]'; };
                                        elements_frames.push(frames[j].frameElement);
                                    }
                                }"
            else
                jssh_command = "var frames = #{@container.element_name}.contentWindow.frames;
                                var elements_frames_#{@@current_level} = new Array();
                                for(var i = 0; i < frames.length; i++)
                                {
                                    elements_frames_#{@@current_level}.push(frames[i].frameElement);
                                }"
            end
            jssh_command +="    var element_name = ''; var object_index = 1;var attribute = '';
                                var element = '';"
            if(@container.class == FireWatir::Firefox)
                jssh_command += "for(var i = 0; i < elements_frames.length; i++)
                                 {
                                    element = elements_frames[i];"
            else
                jssh_command += "for(var i = 0; i < elements_frames_#{@@current_level}.length; i++)
                                 {
                                    element = elements_frames_#{@@current_level}[i];"
            end
            jssh_command += "       if(\"index\" == \"#{how}\")
                                    {
                                        attribute = object_index; object_index += 1;
                                    }
                                    else
                                    {
                                        attribute = element.getAttribute(\"#{how}\");
                                        if(attribute == \"\" || attribute == null)
                                        {
                                            attribute = element.#{how};
                                        }
                                    }
                                    var found = false;"
            if(what.class == Regexp)
                oldRegExp = what.to_s
                newRegExp = "/" + what.source + "/"
                flags = oldRegExp.slice(2, oldRegExp.index(':') - 2)
                for i in 0..flags.length do
                    flag = flags[i, 1]
                    if(flag == '-')
                        break;
                    else
                        newRegExp << flag
                    end
                end
                jssh_command += "   var regExp = new RegExp(#{newRegExp});
                                    found = regExp.test(attribute);"
            elsif(how == :index)
                jssh_command += "   found = (attribute == #{what});"
            else
                jssh_command += "   found = (attribute == \"#{what}\");"
            end
            jssh_command +=     "   if(found)
                                    {"
            if(@container.class == FireWatir::Firefox)
                jssh_command += "       element_name = \"elements_frames[\" + i + \"]\";
                                        #{DOCUMENT_VAR} = elements_frames[i].contentDocument;
                                        #{BODY_VAR} = #{DOCUMENT_VAR}.body;"
            else
                jssh_command += "       element_name = \"elements_frames_#{@@current_level}[\" + i + \"]\";
                                        #{DOCUMENT_VAR} = elements_frames_#{@@current_level}[i].contentDocument;
                                        #{BODY_VAR} = #{DOCUMENT_VAR}.body;"
            end
            jssh_command += "           break;
                                    }
                                }
                                element_name;"
            jssh_command.gsub!("\n", "")
            jssh_socket.send("#{jssh_command};\n", 0)
            element_name = read_socket()
            @@current_level = @@current_level + 1
            if(element_name != "")
                return element_name
            else
                return nil
            end
        end
def locate_frame ( how , what ) jssh_command = "" if ( @container . class == FireWatir :: Firefox ) jssh_command = "var frameset = #{WINDOW_VAR}.frames;
                                var elements_frames = new Array();
                                for(var i = 0; i < frameset.length; i++)
                                {
                                    var frames = frameset[i].frames;
                                    for(var j = 0; j < frames.length; j++)
                                    {
                                        frames[j].frameElement.toString = function() { return '[object HTMLFrameElement]'; };
                                        elements_frames.push(frames[j].frameElement);

                                    }
                                }" else jssh_command = "var frames = #{@container.element_name}.contentWindow.frames;
                                var elements_frames_#{@@current_level} = new Array();
                                for(var i = 0; i < frames.length; i++)
                                {
                                    elements_frames_#{@@current_level}.push(frames[i].frameElement);
                                }" end jssh_command += "    var element_name = ''; var object_index = 1;var attribute = '';
                                var element = '';" if ( @container . class == FireWatir :: Firefox ) jssh_command += "for(var i = 0; i < elements_frames.length; i++)
                                 {
                                    element = elements_frames[i];" else jssh_command += "for(var i = 0; i < elements_frames_#{@@current_level}.length; i++)
                                 {
                                    element = elements_frames_#{@@current_level}[i];" end jssh_command += "       if(\"index\" == \"#{how}\")
                                    {
                                        attribute = object_index; object_index += 1;
                                    }
                                    else
                                    {
                                        attribute = element.getAttribute(\"#{how}\");
                                        if(attribute == \"\" || attribute == null)
                                        {
                                            attribute = element.#{how};
                                        }
                                    }
                                    var found = false;" if ( what . class == Regexp ) oldRegExp = what . to_s newRegExp = "/" + what . source + "/" flags = oldRegExp . slice ( 2 , oldRegExp . index ( ':' ) - 2 ) for i in 0 .. flags . length do flag = flags [ i , 1 ] if ( flag == '-' ) break ; else newRegExp << flag end end jssh_command += "   var regExp = new RegExp(#{newRegExp});
                                    found = regExp.test(attribute);" elsif ( how == :index ) jssh_command += "   found = (attribute == #{what});" else jssh_command += "   found = (attribute == \"#{what}\");" end jssh_command += "   if(found)
                                    {" if ( @container . class == FireWatir :: Firefox ) jssh_command += "       element_name = \"elements_frames[\" + i + \"]\";
                                        #{DOCUMENT_VAR} = elements_frames[i].contentDocument;
                                        #{BODY_VAR} = #{DOCUMENT_VAR}.body;" else jssh_command += "       element_name = \"elements_frames_#{@@current_level}[\" + i + \"]\";
                                        #{DOCUMENT_VAR} = elements_frames_#{@@current_level}[i].contentDocument;
                                        #{BODY_VAR} = #{DOCUMENT_VAR}.body;" end jssh_command += "           break;
                                    }
                                }
                                element_name;" jssh_command . gsub! ( "\n" , "" ) jssh_socket . send ( "#{jssh_command};\n" , 0 ) element_name = read_socket ( ) @@current_level = @@current_level + 1 if ( element_name != "" ) return element_name else return nil end end
Description:
Locates frame element.
Description : Locates frame element .
# Get all the frames the are there on the page.
 #puts "how is #{how} and what is #{what}"
 # In firefox 3 if you write Frame Name then it will not show anything. So we add .toString function to every element.
 #puts "old reg ex is #{what} new reg ex is #{newRegExp}"
 #puts "jssh_command for finding frame is : #{jssh_command}"
 #puts "element_name for frame is : #{element_name}"

how
<not_specific>
what
<not_specific>