Class: FireWatir::TextField

Inherits:
InputElement show all
Defined in:
lib/firewatir/elements/text_field.rb

Overview

Description: Class for Text Field element.

Direct Known Subclasses

Hidden

Constant Summary collapse

INPUT_TYPES =
["text", "password", "textarea"]

Constants inherited from Element

Element::FIRST_ORDERED_NODE_TYPE, Element::NUMBER_TYPE, Element::ORDERED_NODE_ITERATOR_TYPE, Element::TO_S_SIZE

Constants included from Container

Container::DEFAULT_HIGHLIGHT_COLOR, Container::MACHINE_IP

Instance Attribute Summary

Attributes inherited from InputElement

#element_name

Attributes inherited from Element

#element_name

Instance Method Summary collapse

Methods inherited from InputElement

#initialize, #locate

Methods inherited from Element

#assert_enabled, #assert_exists, #attribute_value, #click, #contains_text, #disabled, #document_var, #element_by_xpath, #element_type, #elements_by_xpath, #enabled?, #exists?, #fire_event, #initialize, #inspect, #method_missing, #text, #visible?, #wait

Methods included from Container

#button, #cell, #checkbox, #dd, #dl, #dt, #file_field, #form, #frame, #hidden, #image, #link, #radio, #row, #select_list, #show_all_objects, #table, #text_field

Methods included from JsshSocket

#js_eval, #js_eval_method, #jssh_socket, #read_socket, #valid_js_identifier?

Constructor Details

This class inherits a constructor from FireWatir::InputElement

Dynamic Method Handling

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

Instance Method Details

#append(setThis) ⇒ Object

Description:

Append the provided text to the contents of the text field.
Raises ObjectDisabledException if text field is disabled.
Raises ObjectReadOnlyException if text field is read only.

Input:

- setThis - Text to be appended.


127
128
129
130
131
132
133
134
135
136
137
# File 'lib/firewatir/elements/text_field.rb', line 127

def append( setThis)
  assert_exists
  assert_enabled
  assert_not_readonly

  highlight(:set)
  @o.scrollIntoView
  @o.focus
  doKeyPress( setThis )
  highlight(:clear)
end

#assert_not_readonlyObject

Description:

Checks if object is read-only or not.

Raises:

  • (ObjectReadOnlyException)


43
44
45
# File 'lib/firewatir/elements/text_field.rb', line 43

def assert_not_readonly
  raise ObjectReadOnlyException, "Textfield #{@how} and #{@what} is read only." if self.readonly?
end

#clearObject

Description:

Clears the contents of the text field.
Raises ObjectDisabledException if text field is disabled.
Raises ObjectReadOnlyException if text field is read only.


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

def clear
  assert_exists
  assert_enabled
  assert_not_readonly

  highlight(:set)

  @o.scrollIntoView
  @o.focus
  @o.select()
  @o.fireEvent("onSelect")
  @o.value = ""
  @o.fireEvent("onKeyPress")
  @o.fireEvent("onChange")
  @container.wait()
  highlight(:clear)
end

#maxlengthObject Also known as: maxLength



13
14
15
# File 'lib/firewatir/elements/text_field.rb', line 13

def maxlength
  maxlength_string.to_i
end

#set(setThis) ⇒ Object

Description:

Sets the contents of the text field to the provided text. Overwrite the existing contents.
Raises ObjectDisabledException if text field is disabled.
Raises ObjectReadOnlyException if text field is read only.

Input:

- setThis - Text to be set.


148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/firewatir/elements/text_field.rb', line 148

def set( setThis )
  assert_exists
  assert_enabled
  assert_not_readonly

  highlight(:set)
  @o.scrollIntoView
  @o.focus
  @o.select()
  @o.fireEvent("onSelect")
  @o.value = ""
  @o.fireEvent("onKeyPress")
  doKeyPress( setThis )
  highlight(:clear)
  @o.fireEvent("onChange")
  @o.fireEvent("onBlur")
end

#to_sObject

TODO: Impelement the to_s method.



34
35
36
37
# File 'lib/firewatir/elements/text_field.rb', line 34

def to_s
  assert_exists
  super({"length" => "size","max length" => "maxlength","read only" => "readOnly" })
end

#verify_contains(containsThis) ⇒ Object

Description:

Checks if the provided text matches with the contents of text field. Text can be a string or regular expression.

Input:

- containsThis - Text to verify.

Output:

True if provided text matches with the contents of text field, false otherwise.


57
58
59
60
61
62
63
64
65
# File 'lib/firewatir/elements/text_field.rb', line 57

def verify_contains( containsThis )
  assert_exists
  if containsThis.kind_of? String
    return true if self.value == containsThis
  elsif containsThis.kind_of? Regexp
    return true if self.value.match(containsThis) != nil
  end
  return false
end