Class: Celerity::TextField
- Inherits:
-
InputElement
- Object
- Element
- InputElement
- Celerity::TextField
- Defined in:
- lib/celerity/elements/text_field.rb,
lib/celerity/watir_compatibility.rb
Overview
Class representing text field elements
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
- NON_TEXT_TYPES =
%w[file radio checkbox submit reset image button hidden]
- TAGS =
[ Identifier.new('textarea'), Identifier.new('input', :type => ["text", "password", /^(?!(#{ Regexp.union(*NON_TEXT_TYPES) })$)/]) ]
- DEFAULT_HOW =
:name
Constants inherited from InputElement
Constants inherited from Element
Element::ATTRIBUTES, Element::BASE_ATTRIBUTES, Element::CELLHALIGN_ATTRIBUTES, Element::CELLVALIGN_ATTRIBUTES, Element::HTML_401_TRANSITIONAL
Instance Attribute Summary
Attributes inherited from Element
Attributes included from Container
Instance Method Summary collapse
-
#append(value) ⇒ Object
Append the given value to the text in the text field.
-
#clear ⇒ Object
Clear the text field.
-
#contains_text(expected_text) ⇒ Object
Check if the given text fields contains the given String or Regexp.
-
#drag_contents_to(how, what) ⇒ Object
(also: #dragContentsTo)
This bascially just moves the text to the other text field using TextField#append TODO: check if HtmlUnit supports some kind of dragging.
- #requires_typing ⇒ Object
-
#set(value) ⇒ Object
Set the text field to the given value.
- #type ⇒ Object
-
#value ⇒ Object
(also: #getContents)
Returns the text in the text field.
-
#value=(value) ⇒ Object
This directly sets the text field to the given value, skipping exectuion of JavaScript events.
-
#verify_contains(expected) ⇒ boolean
A boolean version of TextField#contains_text.
- #visible? ⇒ Boolean
Methods inherited from InputElement
Methods included from DisabledElement
#assert_enabled, #disabled?, #enabled?
Methods included from ClickableElement
#click, #click_and_attach, #double_click, #download, #right_click
Methods inherited from Element
#==, #assert_exists, #attribute_string, #attribute_value, #exists?, #fire_event, #focus, #focused?, #initialize, #javascript_object, #locate, #method_missing, #methods, #object, #parent, #respond_to?, #text, #to_s, #to_xml, #xpath
Methods included from Container
#area, #areas, #button, #buttons, #cell, #cells, #check_box, #checkboxes, #container=, #dd, #dds, #del, #dels, #div, #divs, #dl, #dls, #dt, #dts, #em, #ems, #file_field, #file_fields, #form, #forms, #frame, #frames, #h1, #h1s, #h2, #h2s, #h3, #h3s, #h4, #h4s, #h5, #h5s, #h6, #h6s, #hidden, #hiddens, #image, #images, #ins, #inses, #inspect, #label, #labels, #li, #link, #links, #lis, #map, #maps, #meta, #metas, #ol, #ols, #option, #p, #pre, #pres, #ps, #radio, #radios, #row, #rows, #select_list, #select_lists, #span, #spans, #strong, #strongs, #table, #tables, #tbodies, #tbody, #text_field, #text_fields, #tfoot, #tfoots, #th, #thead, #theads, #ths, #ul, #uls
Methods included from ShortInspect
Constructor Details
This class inherits a constructor from Celerity::Element
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Celerity::Element
Instance Method Details
#append(value) ⇒ Object
Append the given value to the text in the text field.
77 78 79 80 81 |
# File 'lib/celerity/elements/text_field.rb', line 77 def append(value) assert_enabled assert_not_readonly type_string value end |
#clear ⇒ Object
Clear the text field.
25 26 27 28 |
# File 'lib/celerity/elements/text_field.rb', line 25 def clear assert_exists insert_string '' end |
#contains_text(expected_text) ⇒ Object
Check if the given text fields contains the given String or Regexp.
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/celerity/elements/text_field.rb', line 107 def contains_text(expected_text) assert_exists case expected_text when Regexp value() =~ expected_text when String value().index(expected_text) else raise TypeError, "expected String or Regexp, got #{expected_text.inspect}:#{expected_text.class}" end end |
#drag_contents_to(how, what) ⇒ Object Also known as: dragContentsTo
This bascially just moves the text to the other text field using TextField#append TODO: check if HtmlUnit supports some kind of dragging.
96 97 98 99 100 101 |
# File 'lib/celerity/elements/text_field.rb', line 96 def drag_contents_to(how, what) assert_exists # assert_enabled? val = self.value self.value = '' @container.text_field(how, what).append(val) end |
#requires_typing ⇒ Object
66 |
# File 'lib/celerity/watir_compatibility.rb', line 66 def requires_typing; end |
#set(value) ⇒ Object
Set the text field to the given value. This ensures execution of JavaScript events (onkeypress etc.), but is slower than value=
35 36 37 38 39 40 41 42 |
# File 'lib/celerity/elements/text_field.rb', line 35 def set(value) assert_enabled assert_not_readonly clear type_string(value.to_s) value end |
#type ⇒ Object
84 85 86 87 88 89 |
# File 'lib/celerity/elements/text_field.rb', line 84 def type assert_exists type = @object.getAttribute 'type' NON_TEXT_TYPES.include?(type) ? type : 'text' end |
#value ⇒ Object Also known as: getContents
Returns the text in the text field.
63 64 65 66 67 68 69 70 71 |
# File 'lib/celerity/elements/text_field.rb', line 63 def value assert_exists case @object.getTagName when 'textarea' @object.getText when 'input' @object.getValueAttribute end end |
#value=(value) ⇒ Object
This directly sets the text field to the given value, skipping exectuion of JavaScript events. Use set
if you want to run events on text fields.
49 50 51 52 53 54 55 56 57 |
# File 'lib/celerity/elements/text_field.rb', line 49 def value=(value) assert_enabled assert_not_readonly clear insert_string value.to_s value end |
#verify_contains(expected) ⇒ boolean
A boolean version of TextField#contains_text
127 128 129 130 |
# File 'lib/celerity/elements/text_field.rb', line 127 def verify_contains(expected) # assert_exists called by contains_text !!contains_text(expected) end |
#visible? ⇒ Boolean
16 17 18 19 |
# File 'lib/celerity/elements/text_field.rb', line 16 def visible? assert_exists type == 'hidden' ? false : super end |