#Grab screen bits
#requires
require 'watir'
#includes
include Watir
#
#Set the page you want WATIR to grab all the fields and buttons for here
#
MYPAGE = "http://loordv01/pls/apex/f?p=102:101"

@@ie = IE.new
@@ie.maximize
#set the speed of watir, we'd also set the speed of light but that's supposed to be a constant
@@ie.speed = :fast

@@ie.goto(MYPAGE)
@@ie.wait
#@@ie.text_field( :id, 'P101_USERNAME' ).set( 'advantica' )
#@@ie.text_field( :id, 'P101_PASSWORD' ).set( 'password' )
#@@ie.button(:id, "login").click
#@@ie.wait

#Get the ole object
doc = @@ie.document
i=0
doc.all.each do |n|

begin
  if n.invoke("type").to_s == 'button'
    davalue = n.invoke('value').to_s
    puts "assert(@@ie.button(:value,'"+davalue+"').exists?,'Could not find "+davalue+" button')"
    i=i+1
  end
  if n.invoke("type").to_s == 'text'or n.invoke("type").to_s == 'textarea'
    davalue = n.invoke('id').to_s
    puts "assert(@@ie.text_field(:id,'"+davalue+"').exists?,'Could not find "+davalue+" field')"
    i=i+1
  end
  if n.invoke("type").to_s == 'select-one'
    davalue = n.invoke('id').to_s
    puts "assert(@@ie.select_list(:id,'"+davalue+"').exists?,'Could not find "+davalue+" select list')"
    i=i+1
  end
  if n.invoke("type").to_s == 'checkbox'
    davalue = n.invoke('id').to_s
    puts "assert(@@ie.checkbox(:id,'"+davalue+"').exists?,'Could not find "+davalue+" checkbox')"
    i=i+1
  end
  if n.invoke("type").to_s == 'radio'
    davalue = n.invoke('id').to_s
    puts "assert(@@ie.radio(:id,'"+davalue+"').exists?,'Could not find "+davalue+" radio button')"
    i=i+1
  end
  if n.invoke("type").to_s == 'file'
    davalue = n.invoke('id').to_s
    puts "assert(@@ie.text_field(:id,'"+davalue+"').exists?,'Could not find "+davalue+" file upload field')"
    i=i+1
  end
    if n.invoke("type").to_s == 'password'
    davalue = n.invoke('id').to_s
    puts "assert(@@ie.text_field(:id,'"+davalue+"').exists?,'Could not find "+davalue+" file upload field')"
    i=i+1
  end
  rescue #if we invoke a type method that doesn't exist get the next element
    next
  end
end
puts "Found #{i} form element(s) on page #{MYPAGE}"