Class: Watir::TextField
- Inherits:
-
InputElement
- Object
- Element
- InputElement
- Watir::TextField
- Defined in:
- lib/watir/input_elements.rb,
lib/watir/camel_case.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 collapse
- INPUT_TYPES =
:stopdoc:
["text", "password", "textarea"]
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.
- #dragContentsTo ⇒ Object
- #maxLength ⇒ 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, #after_text, #assert_enabled, #assert_exists, #attribute_value, #before_text, #click, #click!, #create_event, #dispatch_event, #document, #enabled?, #exists?, #fire_event, #flash, #focus, inherited, #initialize, #inspect, #locate, #method_missing, #name, #ole_object, #ole_object=, #parent, #text, #type_keys, #typingspeed, #visible?
Methods included from Container
#__ole_inner_elements, #input_element_locator, #locator_for, #log, #set_container, #show_all_objects, #tagged_element_locator, #wait
Constructor Details
This class inherits a constructor from Watir::InputElement
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:
401 402 403 404 |
# File 'lib/watir/input_elements.rb', line 401 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
350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/watir/input_elements.rb', line 350 def append(value) assert_exists assert_enabled assert_not_readonly highlight(:set) @o.scrollIntoView @o.focus type_by_character(value) highlight(:clear) end |
#assert_not_readonly ⇒ Object
:nodoc:
274 275 276 277 278 279 |
# File 'lib/watir/input_elements.rb', line 274 def assert_not_readonly #:nodoc: if self.readonly? raise ObjectReadOnlyException, "Textfield #{@how} and #{@what} 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
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/watir/input_elements.rb', line 328 def clear assert_exists assert_enabled assert_not_readonly highlight(:set) @o.scrollIntoView @o.focus @o.select 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
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/watir/input_elements.rb', line 301 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 @o.select value = self.value dispatch_event("onSelect") dispatch_event("ondragstart") dispatch_event("ondrag") 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 |
#dragContentsTo ⇒ Object
58 |
# File 'lib/watir/camel_case.rb', line 58 alias dragContentsTo drag_contents_to |
#maxLength ⇒ Object
57 |
# File 'lib/watir/camel_case.rb', line 57 alias maxLength maxlength |
#maxlength ⇒ Object
return number of maxlength attribute
248 249 250 251 252 253 254 255 |
# File 'lib/watir/input_elements.rb', line 248 def maxlength assert_exists unless @o begin ole_object.invoke('maxlength').to_i rescue WIN32OLERuntimeError 0 end end |
#requires_typing ⇒ Object
:nodoc:
397 398 399 400 |
# File 'lib/watir/input_elements.rb', line 397 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
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/watir/input_elements.rb', line 366 def set(value) assert_exists assert_enabled assert_not_readonly highlight(:set) @o.scrollIntoView if type_keys @o.focus @o.select 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
267 268 269 270 271 272 |
# File 'lib/watir/input_elements.rb', line 267 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.
392 393 394 395 |
# File 'lib/watir/input_elements.rb', line 392 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
287 288 289 290 291 292 293 294 295 |
# File 'lib/watir/input_elements.rb', line 287 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 |