This is where Ruby shines. You will probably need to extend Watir, but that is easy enough.

Here is show_all_objects from watir.rb:
------------------
    def show_all_objects
      puts "-----------Objects in page -------------"
      doc = document
      s = ""
      props = ["name", "id", "value", "alt", "src"]
      doc.all.each do |n|
        begin
          s += n.invoke("type").to_s.ljust(16)
        rescue
          next
        end
        props.each do |prop|
          begin
            p = n.invoke(prop)
            s += "  " + "#{prop}=#{p}".to_s.ljust(18)
          rescue
            # this object probably doesnt have this property
          end
        end
        s += "\n"
      end
      puts s
    end
------------------

You can see that it explicitly uses "puts" to print to stdout. Instead, what you probably want is a string. That could hardly be simpler. All you need to do is replace the second-to-last line ("puts s") with just "s". That will return the string rather than printing it.

So, just do this in your code:

  class Watir::IE
    def get_all_objects
      < body of code from above (between the "def" and "end" lines) goes here >
    end
  end


Then replace the "puts s" with "s" in that method, and you now have a new Watir method. If your IE object is called @ie, you can do:

my_objects_string = @ie.get_all_objects

As a side note, it appears to me that the show_all_objects method really belongs within "Container" rather than "IE", but that is a separate matter.

Lonny Eachus
==========


Subject:
Re: [Wtr-general] Writing the output of show all objects to a file
From:
SRK <[EMAIL PROTECTED]>
Date:
Wed, 9 Aug 2006 18:13:35 +0100 (BST)

Thanks, but the in the text file only the value "nil" is recorded and the objects are not getting recorded.

Nandan <[EMAIL PROTECTED]> wrote:
Is this what you mean?

outp = File.open("out.txt", "w")
sr = ie.show_all_objects
outp.puts sr
outp.close
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.openqa.org/thread.jspa?threadID=3375&messageID=9406#9406
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general


_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to