Class: Watir::Form

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

Constant Summary

Constants inherited from Element

Element::TO_S_SIZE

Instance Attribute Summary

Attributes inherited from Element

#container

Attributes included from Container

#activeObjectHighLightColor, #page_container, #type_keys, #typingspeed

Instance Method Summary collapse

Methods inherited from Element

#<=>, #activeObjectHighLightColor, #after_text, #assert_enabled, #assert_exists, #attribute_value, #before_text, #click, #click!, #create_event, #dispatch_event, #document, #enabled?, #exists?, #fire_event, #focus, inherited, #inspect, #method_missing, #ole_object, #ole_object=, #parent, #text, #to_s, #type_keys, #typingspeed, #visible?

Methods included from Container

#input_element_locator, #locator_for, #log, #set_container, #show_all_objects, #tagged_element_locator, #wait

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



7
8
9
10
11
12
# File 'lib/watir/form.rb', line 7

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 Method Details

#__ole_inner_elementsObject



46
47
48
49
# File 'lib/watir/form.rb', line 46

def __ole_inner_elements
  assert_exists
  @o.elements
end

#flash(number = 10) ⇒ Object

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



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/watir/form.rb', line 80

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

#form_methodObject



22
23
24
25
# File 'lib/watir/form.rb', line 22

def form_method
  assert_exists
  @o.invoke('method')
end

#locateObject



35
36
37
# File 'lib/watir/form.rb', line 35

def locate
  @o = @container.locator_for(FormLocator, @how, @what).locate
end

#method(arg = nil) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/watir/form.rb', line 27

def method(arg = nil)
  if arg.nil?
    form_method
  else
    super(arg)
  end
end

#nameObject



16
17
18
19
20
# File 'lib/watir/form.rb', line 16

def name
  assert_exists
  name = @o.getAttributeNode('name')
  name ? name.value : ''
end

#submitObject

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



40
41
42
43
44
# File 'lib/watir/form.rb', line 40

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