Class: Watir::Form

Inherits:
Element show all
Defined in:
lib/watir-classic/form.rb

Overview

Returned by Container#form.

Instance Attribute Summary

Attributes inherited from Element

#container

Attributes included from Container

#page_container

Instance Method Summary collapse

Methods inherited from Element

#<=>, #attribute_value, #class_name, #click, #disabled?, #double_click, #enabled?, #exists?, #fire_event, #focus, #focused?, #html, #id, #inspect, #method_missing, #ole_object, #parent, #right_click, #send_keys, #style, #tag_name, #text, #title, #to_s, #to_subtype, #unique_number, #visible?

Methods included from DragAndDropHelper

#drag_and_drop_by, #drag_and_drop_on

Methods included from Container

#a, #abbr, #address, #alert, #area, #article, #aside, #audio, #b, #base, #bdi, #bdo, #blockquote, #body, #br, #button, #canvas, #caption, #checkbox, #cite, #code, #col, #colgroup, #command, #data, #datalist, #dd, #del, #details, #dfn, #div, #dl, #dt, #element, #em, #embed, #fieldset, #figcaption, #figure, #file_field, #font, #footer, #form, #frame, #frameset, #h1, #h2, #h3, #h4, #h5, #h6, #head, #header, #hgroup, #hidden, #hr, #i, #img, #input, #ins, #kbd, #keygen, #label, #legend, #li, #map, #mark, #menu, #meta, #meter, #modal_dialog, #nav, #noscript, #object, #ol, #optgroup, #option, #output, #p, #param, #pre, #progress, #q, #radio, #rp, #rt, #ruby, #s, #samp, #script, #section, #select, #small, #source, #span, #strong, #style, #sub, #summary, #sup, #table, #tbody, #td, #text_field, #textarea, #tfoot, #th, #thead, #time, #title, #tr, #track, #u, #ul, #var, #video, #wbr

Methods included from Exception

message_for_unable_to_locate

Methods included from ElementExtensions

#present?, #wait_until_present, #wait_while_present, #when_present

Constructor Details

#initialize(container, specifiers) ⇒ Form

Returns a new instance of Form.



8
9
10
11
# File 'lib/watir-classic/form.rb', line 8

def initialize(container, specifiers)
  super
  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

#flash(number = 10) ⇒ Object

Flash the element the specified number of times for troubleshooting purposes.

Parameters:

  • number (Fixnum) (defaults to: 10)

    number of times to flash the element.



52
53
54
55
56
57
58
59
60
61
# File 'lib/watir-classic/form.rb', line 52

def flash(number=10)
  assert_exists
  @original_element_colors = {}
  number.times do
    set_highlight
    sleep 0.05
    clear_highlight
    sleep 0.05
  end
end

#form_methodString

Returns form method attribute value.

Returns:

  • (String)

    form method attribute value.



24
25
26
27
# File 'lib/watir-classic/form.rb', line 24

def form_method
  assert_exists
  ole_object.invoke('method')
end

#method(arg = nil) ⇒ Object

Parameters:

  • arg (Object) (defaults to: nil)

    when argument is nil, #form_method will be called. Otherwise Ruby’s Kernel#method will be called.



31
32
33
34
35
36
37
# File 'lib/watir-classic/form.rb', line 31

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

#nameString

Returns form name attribute value. Will be empty string if does not exist.

Returns:

  • (String)

    form name attribute value. Will be empty string if does not exist.



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

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

#submitObject

Note:

Will not submit the form if its onSubmit JavaScript callback returns false.

Submit the form.



43
44
45
46
47
# File 'lib/watir-classic/form.rb', line 43

def submit 
  assert_exists
  @o.submit(0) if dispatch_event "onSubmit"
  @container.wait
end