Good work. Can you submit patch for it?

Thanks,
Angrez

On Wed, Jun 24, 2009 at 3:56 PM, dottree <yuanchun.l...@gmail.com> wrote:

>
> ====Senario: Get sub frames====
> <iframe>
>    <iframe>..</iframe>
>    <iframe>..</iframe>
> </iframe>
>
> ====Issue1. Firewatir has no get frames collection function:====
> Add frames()
> ------------------------
> class Document
>  def frames
>    return Frames.new(@container)
>  end
> end
> ------------------------
> Also add documet()function and attribute "TAG" for Frame class
> --------------------------
> module FireWatir
>  class Frame < Element
>    def document
>       Document.new(self)
>    end
>
>    TAG = 'IFRAME'
>  end
> end
> --------------------------
>
> ====Issue2. It always returns the top level frames not the subframes
> when calling frames()=====
> Rewrite "ElementCollections.locate_tagged_elements()" funciton.
> -------------------------
> class ElementCollections
>  def locate_tagged_elements(tag, types = [])
>
>  # generate array to hold results
>  result_name = "arr_coll_#{tag}_#{@@current_level}"
>  jssh_command = "var #{result_name}=new Array();"
>
>  if types.include?("textarea") || types.include?("button")
>    search_tag = '*'
>  else
>    search_tag = tag
>  end
>
>  # generate array of elements matching the tag
>  if @container.class == FireWatir::Firefox || @container.class ==
> FireWatir::Frame && tag.upcase != "IFRAME"
>    elements_tag = "elements_#{tag}"
>    container_name = DOCUMENT_VAR
>    jssh_command += "var #{elements_tag} = null; "
>    jssh_command += "#{elements_tag} = #
> {container_name}.getElementsByTagName(\"#{search_tag}\");"
>  elsif @container.class == FireWatir::Frame && tag.upcase == "IFRAME"
>    elements_tag = "elements_#{@@current_level}_#{tag}"
>    container_name = "#...@container.element_name}"
>    jssh_command += "var #{elements_tag} = null; "
>    jssh_command += "#{elements_tag} = #
> {container_name}.contentWindow.frames;"
>  else
>    elements_tag = "elements_#{@@current_level}_#{tag}"
>    container_name = "#...@container.element_name}"
>    jssh_command += "var #{elements_tag} = null; "
>    jssh_command += "#{elements_tag} = #
> {container_name}.getElementsByTagName(\"#{search_tag}\");"
>  end
>
>  # generate array containing results
>  if types.empty?
>    jssh_command += "#{result_name} = #{elements_tag};"
>  else
>    # generate types array
>    jssh_command += "var types = new Array("
>    types.each_with_index do |type, count|
>      jssh_command += "," unless count == 0
>      jssh_command += "\"#{type}\""
>    end
>    jssh_command += ");"
>
>    # check the type of each element
>    jssh_command += "for(var i=0; i<#{elements_tag}.length; i++)
>                       {
>                          var element = #{elements_tag}[i];
>                          var same_type = false;
>
>                          for(var j=0; j<types.length; j++)
>                          {
>                              if(types[j] == element.type || types[j]
> == element.tagName)
>                              {
>                                  same_type = true;
>                                  break;
>                              }
>                          }
>
>                          if(same_type)
>                          {
>                              #{result_name}.push(element);
>                          }
>                      };"
>  end
>  jssh_command += "#{result_name}.length;"
>
>  # Remove \n that are there in the string as a result of pressing
> enter while formatting.
>  jssh_command.gsub!(/\n/, "")
>  #puts jssh_command
>  jssh_socket.send("#{jssh_command};\n", 0)
>  length = read_socket().to_i;
>  puts jssh_command
>  puts "elements length is in locate_tagged_elements is : #{length}"
>
>  elements = (0...length).collect {|i| "#{result_name}[#{i}]"}
>
>  @@current_level = @@current_level + 1
>  return elements
> end
> private :locate_tagged_elements
> end
> ----------------------------------------------
>
> ==How to use it
> innerframes = ff.frame("a").document.frames
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~----------~----~----~----~------~----~------~--~---

Reply via email to