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
#<=>, #activeObjectHighLightColor, #after_text, #assert_enabled, #assert_exists, #attribute_value, #before_text, #click, #click!, #click_no_wait, #document, #enabled?, #exists?, #fire_event, #flash, #focus, #initialize, #inspect, #ole_object, #ole_object=, #parent, #text, #type_keys, #typingspeed, #visible?
Methods included from Container
#area, #areas, #button, #buttons, #cell, #cells, #checkbox, #checkboxes, #dds, #divs, #dls, #dts, #element, #elements, #ems, #file_field, #file_fields, #form, #forms, #frame, #hidden, #hiddens, #image, #images, #labels, #link, #links, #lis, #locate_all_elements, #locate_input_element, #locate_tagged_element, #log, #map, #maps, #modal_dialog, #popup, #pres, #ps, #radio, #radios, #row, #rows, #select_list, #select_lists, #set_container, #show_all_objects, #spans, #strongs, #table, #tables, #text_field, #text_fields, #wait
Constructor Details
This class inherits a constructor from Watir::InputElement
Instance Method Details
#abhors_typing ⇒ Object
:nodoc:
397 398 399 400 |
# File 'lib/watir/input_elements.rb', line 397 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
348 349 350 351 352 353 354 355 356 357 |
# File 'lib/watir/input_elements.rb', line 348 def append(value) assert_enabled assert_not_readonly highlight(:set) @o.scrollIntoView @o.focus type_by_character(value) highlight(:clear) end |
#assert_not_readonly ⇒ Object
:nodoc:
273 274 275 276 277 278 |
# File 'lib/watir/input_elements.rb', line 273 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
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/watir/input_elements.rb', line 327 def clear 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 |
#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
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/watir/input_elements.rb', line 300 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 @o.fireEvent("onSelect") @o.fireEvent("ondragstart") @o.fireEvent("ondrag") destination.fireEvent("onDragEnter") destination.fireEvent("onDragOver") destination.fireEvent("ondrop") @o.fireEvent("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
247 248 249 250 251 252 253 254 |
# File 'lib/watir/input_elements.rb', line 247 def maxlength assert_exists begin ole_object.invoke('maxlength').to_i rescue WIN32OLERuntimeError 0 end end |
#requires_typing ⇒ Object
:nodoc:
393 394 395 396 |
# File 'lib/watir/input_elements.rb', line 393 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
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/watir/input_elements.rb', line 363 def set(value) assert_enabled assert_not_readonly highlight(:set) @o.scrollIntoView if type_keys @o.focus @o.select @o.fireEvent("onSelect") @o.fireEvent("onKeyPress") @o.value = "" type_by_character(value) @o.fireEvent("onChange") @o.fireEvent("onBlur") else @o.value = limit_to_maxlength(value) end highlight(:clear) end |
#to_s ⇒ Object
266 267 268 269 270 271 |
# File 'lib/watir/input_elements.rb', line 266 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.
388 389 390 391 |
# File 'lib/watir/input_elements.rb', line 388 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
286 287 288 289 290 291 292 293 294 |
# File 'lib/watir/input_elements.rb', line 286 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 |