Class: Celerity::TextField
- Celerity::Element
- Celerity::InputElement
- Celerity::TextField
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
Constants
- DEFAULT_HOW
- :name
- 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) })$)/]) ]
Constants Inherited from Celerity::InputElement
Constants Inherited from Celerity::Element
BASE_ATTRIBUTES, CELLHALIGN_ATTRIBUTES, CELLVALIGN_ATTRIBUTES, HTML_401_TRANSITIONAL, TO_S_SIZE
Constructor Summary
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
Dynamically get element attributes.
235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/celerity/element.rb', line 235 def method_missing(meth, *args, &blk) assert_exists meth = selector_to_attribute(meth) if self.class::ATTRIBUTES.include?(meth) || (self.class == Element && @object.hasAttribute(meth.to_s)) return @object.getAttribute(meth.to_s) end Log.warn "Element\#method_missing calling super with #{meth.inspect}" super end |
Public Visibility
Public Instance Method Summary
#append(value) |
Append the given value to the text in the text field. |
---|---|
#clear |
Clear the text field. |
#contains_text(expected_text) |
Check if the given text fields contains the given String or Regexp. |
#drag_contents_to(how, what) #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 | |
#set(value) |
Set the text field to the given value. |
#type | |
#value #getContents #get_contents |
Returns the text in the text field. |
#verify_contains(expected) |
A boolean version of TextField#contains_text. Returns: boolean |
#visible? |
Public Instance Methods Inherited from Celerity::InputElement
Public Instance Methods Inherited from Celerity::Element
assert_exists, attribute_string, attribute_value, exists?, fire_event, focus, locate, methods, object, parent, respond_to?, text, to_s, to_xml, xpath
Public Instance Method Details
append
Append the given value to the text in the text field.
76 77 78 79 80 |
# File 'lib/celerity/elements/text_field.rb', line 76 def append(value) assert_enabled assert_not_readonly type_string(value) end |
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 |
contains_text
Check if the given text fields contains the given String or Regexp.
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/celerity/elements/text_field.rb', line 110 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
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.
99 100 101 102 103 104 |
# File 'lib/celerity/elements/text_field.rb', line 99 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
82 |
# File 'lib/celerity/watir_compatibility.rb', line 82 def requires_typing; end |
set
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 |
# File 'lib/celerity/elements/text_field.rb', line 35 def set(value) assert_enabled assert_not_readonly clear type_string(value.to_s) end |
type
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/celerity/elements/text_field.rb', line 83 def type assert_exists type = @object.getAttribute 'type' if NON_TEXT_TYPES.include?(type) type else 'text' end end |
value
Also known as: getContents get_contents
Returns the text in the text field.
47 48 49 50 51 52 53 54 55 |
# File 'lib/celerity/elements/text_field.rb', line 47 def value assert_exists case @object.getTagName when 'textarea' @object.getText when 'input' @object.getValueAttribute end end |
verify_contains
A boolean version of TextField#contains_text
129 130 131 132 |
# File 'lib/celerity/elements/text_field.rb', line 129 def verify_contains(expected) # assert_exists called by contains_text !!contains_text(expected) end |
visible?
16 17 18 19 |
# File 'lib/celerity/elements/text_field.rb', line 16 def visible? assert_exists type == 'hidden' ? false : super end |