Class: Celerity::TextField
- Inherits:
-
Celerity::InputElement
- Object
- Celerity::Element
- Celerity::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
Constant Summary
- 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 Celerity::InputElement
Constants inherited from Celerity::Element
ATTRIBUTES, BASE_ATTRIBUTES, CELLHALIGN_ATTRIBUTES, CELLVALIGN_ATTRIBUTES, DEFAULT_HOW, HTML_401_TRANSITIONAL, TAGS
Method Summary
- - (Object) append(value) Append the given value to the text in the text field.
- - (Object) clear Clear the text field.
- - (Object) contains_text(expected_text) Check if the given text fields contains the given String or Regexp.
- - (Object) drag_contents_to(how, what) (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.
- - (Object) requires_typing
- - (Object) set(value) Set the text field to the given value.
- - (Object) type
- - (Object) value (also: #getContents) Returns the text in the text field.
- - (Object) value=(value) This directly sets the text field to the given value, skipping exectuion of JavaScript events.
- - (boolean) verify_contains(expected) A boolean version of TextField#contains_text.
- - (Object) visible?
Methods inherited from Celerity::InputElement
#assert_not_readonly, #readonly?
Methods included from Celerity::ClickableElement
#assert_exists_and_enabled, #click, #click_and_attach, #double_click, #download, #right_click
Methods included from Celerity::DisabledElement
#assert_enabled, #disabled?, #enabled?
Methods inherited from Celerity::Element
#==, #assert_exists, #attribute_string, #attribute_value, #exists?, #fire_event, #focus, #identifier_string, #initialize, #javascript_object, #locate, #method_missing, #methods, #object, #parent, #respond_to?, #selector_to_attribute, #text, #to_s, #to_xml, #xpath
Methods included from Celerity::Container
#area, #areas, #button, #buttons, #cell, #cells, #check_box, #checkboxes, #container=, #dd, #dds, #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, #inspect, #label, #labels, #li, #link, #links, #lis, #map, #maps, #meta, #metas, #ol, #ols, #option, #p, #pre, #pres, #ps, #radio, #radios, #rescue_status_code_exception, #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 Celerity::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
Method Details
- (Object) append(value)
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 |
- (Object) clear
Clear the text field.
25 26 27 28 |
# File 'lib/celerity/elements/text_field.rb', line 25 def clear assert_exists insert_string '' end |
- (Object) contains_text(expected_text)
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 |
- (Object) drag_contents_to(how, what) 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 |
- (Object) requires_typing
66 |
# File 'lib/celerity/watir_compatibility.rb', line 66 def requires_typing; end |
- (Object) set(value)
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 |
- (Object) type
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 |
- (Object) value 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 |
- (Object) value=(value)
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 |
- (boolean) verify_contains(expected)
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 |
- (Object) visible?
16 17 18 19 |
# File 'lib/celerity/elements/text_field.rb', line 16 def visible? assert_exists type == 'hidden' ? false : super end |