|
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 ==========
|
_______________________________________________ Wtr-general mailing list [email protected] http://rubyforge.org/mailman/listinfo/wtr-general
