Class: Watir::Form

Inherits:
FormElement show all
Includes:
Container
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, #element_by_css, #elements, #ems, #file_field, #file_fields, #forms, #frame, #frames, #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, #wait

Methods inherited from FormElement

#form_method, #method, #name

Methods inherited from Element

#<=>, #activeObjectHighLightColor, #after_text, #assert_enabled, #assert_exists, #attribute_value, #before_text, #click, #click!, #document, #enabled?, #exists?, #fire_event, #focus, #inspect, #method_missing, #ole_object, #ole_object=, #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



36
37
38
39
40
41
# File 'lib/watir/form.rb', line 36

def initialize(container, how, what)
  set_container container
  @how = how
  @what = what
  copy_test_config container
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Watir::Element

Instance Attribute Details

#formObject

Returns the value of attribute form.



31
32
33
# File 'lib/watir/form.rb', line 31

def form
  @form
end

Instance Method Details

#flash(number = 10) ⇒ Object

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



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/watir/form.rb', line 100

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

#locateObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/watir/form.rb', line 43

def locate
  log "Get form how is #{@how}  what is #{@what} "

  # Get form using xpath.

  if @how == :xpath
    @o = @container.element_by_xpath(@what)
  elsif @how == :css
    @o = @container.element_by_css(@what)
  else
    locator = FormLocator.new(@container, 'FORM')
    locator.set_specifier(@how, @what)
    @o = locator.locate
  end
end

#submitObject

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



59
60
61
62
63
# File 'lib/watir/form.rb', line 59

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