I do not know if this is related to your problem, but I had trouble with show_all_objects because I expected it to return a string, but it does not.

To get a string instead (which you can print yourself, or put in an array . . .), you can add a new method to Watir:

class Watir::IE
  def get_all_objects
    #puts "-----------Objects in  page -------------"
    doc = ie.document
    s = ""
    props=["name" ,"id" , "value" , "alt" , "src"]
    doc.all.each do |n|
      begin
        s = s + n.invoke("type").to_s.ljust(16)
      rescue
        next
      end
      props.each do |prop|
        begin
          p = n.invoke(prop)
          s = s + "  " + "#{prop}=#{p}".to_s.ljust(18)
        rescue
          # this object probably doesnt have this property
        end
      end
      s = s + "\n"
    end
    # s + "\n\n\n"
    s     # Just return the string.
  end
end

Name it anything you want. This is just show_all_objects(), modified to return a string. You can also remove items from the "props" array if you are just looking for specific things like name or id. So you could have "get_all_ids()" or "get_all_names()" for example.

Put this in a .rb file somewhere in your project. Your /lib directory is a good place. You could make a /lib.w_extensions.rb for example.


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

Subject:
[Wtr-general] Locating HTML objects
From:
Adrian Rutter <[EMAIL PROTECTED]>
Date:
Fri, 26 May 2006 10:30:14 +0100

Hi,

I am trying to locate some objects on my HTML page. I have used the method
show_all_objects, but on the command screen I am just getting a freeze on
this:

<snip>

C:\Program Files\Watir\Watir_Tests>ruby addCustomer.rb
-----------Objects in  page -------------

<snip>
  

_______________________________________________
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to