Class: Watir::Form

Inherits:
Element show all
Includes:
Container, FormAccess
Defined in:
lib/watir/form.rb,
lib/watir/camel_case.rb

Overview

Form Factory object

Constant Summary

Constants inherited from Element

Element::TO_S_SIZE

Instance Attribute Summary collapse

Attributes included from Container

#activeObjectHighLightColor, #page_container, #type_keys, #typingspeed

Attributes inherited from Element

#container

Instance Method Summary collapse

Methods included from Container

#area, #areas, #button, #buttons, #cell, #cells, #checkbox, #checkboxes, #dds, #divs, #dls, #dts, #element, #elements, #ems, #file_field, #file_fields, #forms, #frame, #hidden, #hiddens, #image, #images, #labels, #link, #links, #lis, #locate_all_elements, #locate_input_element, #locate_tagged_element, #log, #map, #maps, #modal_dialog, #popup, #pres, #ps, #radio, #radios, #row, #rows, #select_list, #select_lists, #set_container, #show_all_objects, #spans, #strongs, #table, #tables, #text_field, #text_fields

Methods included from FormAccess

#action, #id, #method, #name

Methods inherited from Element

#<=>, #activeObjectHighLightColor, #after_text, #assert_enabled, #attribute_value, #before_text, #click, #click!, #click_no_wait, #enabled?, #fire_event, #focus, #inspect, #parent, #text, #to_s, #type_keys, #typingspeed, #visible?

Constructor Details

#initialize(container, how, what) ⇒ Form

  • container - the containing object, normally an instance of IE

    • how - symbol - how we access the form (:name, :id, :index, :action, :method)

    • what - what we use to access the form



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/watir/form.rb', line 38

def initialize(container, how, what)
  set_container container
  @how = how
  @what = what
  
  log "Get form how is #{@how}  what is #{@what} "
  
  # Get form using xpath.

  if @how == :xpath
    @ole_object = @container.element_by_xpath(@what)
  else
    count = 1
    doc = @container.document
    doc.forms.each do |thisForm|
      next unless @ole_object == nil
      
      wrapped = FormWrapper.new(thisForm)
      @ole_object =
      case @how
      when :name, :id, :method, :action
        @what.matches(wrapped.send(@how)) ? thisForm : nil
      when :index
        count == @what ? thisForm : nil
      else
        raise MissingWayOfFindingObjectException, "#{how} is an unknown way of finding a form (#{what})"
      end
      count += 1
    end
  end
  super(@ole_object)
  
  copy_test_config container
end

Instance Attribute Details

#formObject

Returns the value of attribute form.



33
34
35
# File 'lib/watir/form.rb', line 33

def form
  @form
end

#ole_objectObject

Returns the value of attribute ole_object.



33
34
35
# File 'lib/watir/form.rb', line 33

def ole_object
  @ole_object
end

Instance Method Details

#assert_existsObject



77
78
79
80
81
82
# File 'lib/watir/form.rb', line 77

def assert_exists
  unless exists?
    raise UnknownFormException, 
      "Unable to locate a form using #{@how} and #{@what}" 
  end
end

#documentObject



97
98
99
# File 'lib/watir/form.rb', line 97

def document
  return @ole_object
end

#exists?Boolean Also known as: exist?

Returns:

  • (Boolean)


72
73
74
# File 'lib/watir/form.rb', line 72

def exists?
  @ole_object ? true : false
end

#flash(number = 10) ⇒ Object

causes the object to flash. Normally used in IRB when creating scripts Default is 10



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/watir/form.rb', line 135

def flash number=10
  @original_styles = {}
  number.times do
    count = 0
    @ole_object.elements.each do |element|
      highlight(:set, element, count)
      count += 1
    end
    sleep 0.05
    count = 0
    @ole_object.elements.each do |element|
      highlight(:clear, element, count)
      count += 1
    end
    sleep 0.05
  end
end

#submitObject

Submit the data – equivalent to pressing Enter or Return to submit a form.



85
86
87
88
89
# File 'lib/watir/form.rb', line 85

def submit 
  assert_exists
  @ole_object.invoke('submit')
  @container.wait
end

#wait(no_sleep = false) ⇒ Object Also known as: waitForIE



101
102
103
# File 'lib/watir/form.rb', line 101

def wait(no_sleep=false)
  @container.wait(no_sleep)
end