Class: Watir::TextField
- Inherits:
-
InputElement
- Object
- Element
- InputElement
- Watir::TextField
- Defined in:
- lib/watir-classic/input_elements.rb
Overview
This class is the main class for Text Fields Normally a user would not need to create this object as it is returned by the Watir::Container#text_field method
Direct Known Subclasses
Constant Summary
Constants inherited from Element
Instance Attribute Summary
Attributes inherited from Element
Attributes included from Container
#activeObjectHighLightColor, #page_container, #type_keys, #typingspeed
Instance Method Summary collapse
-
#abhors_typing ⇒ Object
:nodoc:.
-
#append(value) ⇒ Object
Appends the specified string value to the contents of the text box.
-
#assert_not_readonly ⇒ Object
:nodoc:.
-
#clear ⇒ Object
Clears the contents of the text box.
-
#drag_contents_to(destination_how, destination_what) ⇒ Object
Drag the entire contents of the text field to another text field 19 Jan 2005 - It is added as prototype functionality, and may change * destination_how - symbol, :id, :name how we identify the drop target * destination_what - string or regular expression, the name, id, etc of the text field that will be the drop target.
- #label ⇒ Object
-
#maxlength ⇒ Object
return number of maxlength attribute.
-
#requires_typing ⇒ Object
:nodoc:.
-
#set(value) ⇒ Object
Sets the contents of the text box to the specified text value Raises UnknownObjectException if the object cant be found Raises ObjectDisabledException if the object is disabled Raises ObjectReadOnlyException if the object is read only.
- #to_s ⇒ Object
-
#value=(v) ⇒ Object
Sets the value of the text field directly.
-
#verify_contains(target) ⇒ Object
Returns true if the text field contents is matches the specified target, which can be either a string or a regular expression.
Methods inherited from InputElement
Methods inherited from Element
#<=>, #__ole_inner_elements, #activeObjectHighLightColor, #assert_enabled, #assert_exists, #attribute_value, #click, #click!, #create_event, #disabled?, #dispatch_event, #document, #double_click, #enabled?, #exists?, #fire_event, #flash, #focus, #focused?, #initialize, #inspect, #locate, #method_missing, #ole_object, #ole_object=, #parent, #right_click, #send_keys, #style, #tag_name, #to_subtype, #type_keys, #typingspeed, #visible?
Methods included from DragAndDropHelper
#drag_and_drop_by, #drag_and_drop_on
Methods included from Container
#__ole_inner_elements, #alert, #locator_for, #modal_dialog, #set_container, support_element, #wait
Methods included from Exception
Methods included from ElementExtensions
#present?, #wait_until_present, #wait_while_present, #when_present
Constructor Details
This class inherits a constructor from Watir::Element
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Watir::Element
Instance Method Details
#abhors_typing ⇒ Object
:nodoc:
321 322 323 324 |
# File 'lib/watir-classic/input_elements.rb', line 321 def abhors_typing #:nodoc: @type_keys = false self end |
#append(value) ⇒ Object
Appends the specified string value to the contents of the text box.
Raises UnknownObjectException if the object cant be found
Raises ObjectDisabledException if the object is disabled
Raises ObjectReadOnlyException if the object is read only
270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/watir-classic/input_elements.rb', line 270 def append(value) assert_exists assert_enabled assert_not_readonly highlight(:set) @o.scrollIntoView @o.focus(0) type_by_character(value) highlight(:clear) end |
#assert_not_readonly ⇒ Object
:nodoc:
193 194 195 196 197 198 |
# File 'lib/watir-classic/input_elements.rb', line 193 def assert_not_readonly #:nodoc: if self.readonly? raise ObjectReadOnlyException, "Textfield #{@specifiers.inspect} is read only." end end |
#clear ⇒ Object
Clears the contents of the text box.
Raises UnknownObjectException if the object can't be found
Raises ObjectDisabledException if the object is disabled
Raises ObjectReadOnlyException if the object is read only
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/watir-classic/input_elements.rb', line 248 def clear assert_exists assert_enabled assert_not_readonly highlight(:set) @o.scrollIntoView @o.focus(0) @o.select(0) dispatch_event("onSelect") @o.value = "" dispatch_event("onKeyPress") dispatch_event("onChange") @container.wait highlight(:clear) end |
#drag_contents_to(destination_how, destination_what) ⇒ Object
Drag the entire contents of the text field to another text field
19 Jan 2005 - It is added as prototype functionality, and may change
* destination_how - symbol, :id, :name how we identify the drop target
* destination_what - string or regular expression, the name, id, etc of the text field that will be the drop target
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/watir-classic/input_elements.rb', line 220 def drag_contents_to(destination_how, destination_what) assert_exists destination = @container.text_field(destination_how, destination_what) unless destination.exists? raise UnknownObjectException, "Unable to locate destination using #{destination_how } and #{destination_what } " end @o.focus(0) @o.select(0) value = self.value dispatch_event("onSelect") dispatch_event("ondragstart") dispatch_event("ondrag") destination.assert_exists destination.dispatch_event("onDragEnter") destination.dispatch_event("onDragOver") destination.dispatch_event("ondrop") dispatch_event("ondragend") destination.value = destination.value + value.to_s self.value = "" end |
#label ⇒ Object
326 327 328 |
# File 'lib/watir-classic/input_elements.rb', line 326 def label @container.label(:for => name).text end |
#maxlength ⇒ Object
return number of maxlength attribute
168 169 170 171 172 173 174 175 |
# File 'lib/watir-classic/input_elements.rb', line 168 def maxlength assert_exists unless @o begin ole_object.invoke('maxlength').to_i rescue WIN32OLERuntimeError 0 end end |
#requires_typing ⇒ Object
:nodoc:
317 318 319 320 |
# File 'lib/watir-classic/input_elements.rb', line 317 def requires_typing #:nodoc: @type_keys = true self end |
#set(value) ⇒ Object
Sets the contents of the text box to the specified text value
Raises UnknownObjectException if the object cant be found
Raises ObjectDisabledException if the object is disabled
Raises ObjectReadOnlyException if the object is read only
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/watir-classic/input_elements.rb', line 286 def set(value) assert_exists assert_enabled assert_not_readonly highlight(:set) @o.scrollIntoView if type_keys @o.focus(0) @o.select(0) dispatch_event("onSelect") dispatch_event("onKeyPress") @o.value = "" type_by_character(value) dispatch_event("onChange") dispatch_event("onBlur") else @o.value = limit_to_maxlength(value) end highlight(:clear) end |
#to_s ⇒ Object
186 187 188 189 190 191 |
# File 'lib/watir-classic/input_elements.rb', line 186 def to_s assert_exists r = string_creator r += text_string_creator r.join("\n") end |
#value=(v) ⇒ Object
Sets the value of the text field directly. It causes no events to be fired or exceptions to be raised, so generally shouldn’t be used. It is preffered to use the set method.
312 313 314 315 |
# File 'lib/watir-classic/input_elements.rb', line 312 def value=(v) assert_exists @o.value = v.to_s end |
#verify_contains(target) ⇒ Object
Returns true if the text field contents is matches the specified target, which can be either a string or a regular expression.
Raises UnknownObjectException if the object can't be found
– I vote for deprecating this we should use text_field().text.include?(some) or text.match(/some/) instead of this method
206 207 208 209 210 211 212 213 214 |
# File 'lib/watir-classic/input_elements.rb', line 206 def verify_contains(target) #:nodoc: assert_exists if target.kind_of? String return true if self.value == target elsif target.kind_of? Regexp return true if self.value.match(target) != nil end return false end |