Module: Watir::UserEditable
Instance Method Summary collapse
-
#append(*args) ⇒ Object
(also: #<<)
Appends the given value to the text in the text field.
-
#clear ⇒ Object
Clears the text field.
-
#content_editable ⇒ Boolean
Returns true if element is user_editable because it has a content_editable attribute set.
-
#set(*args) ⇒ Object
(also: #value=)
Clear the element, then type in the given value.
-
#set!(*args) ⇒ Object
Uses JavaScript to enter most of the given value.
Instance Method Details
#append(*args) ⇒ Object Also known as: <<
Appends the given value to the text in the text field.
58 59 60 61 62 |
# File 'lib/watir/user_editable.rb', line 58 def append(*args) raise NotImplementedError, '#append method is not supported with contenteditable element' if content_editable send_keys(*args) end |
#clear ⇒ Object
Clears the text field.
69 70 71 72 73 |
# File 'lib/watir/user_editable.rb', line 69 def clear element_call(:wait_for_writable) do @element.clear end end |
#content_editable ⇒ Boolean
Returns true if element is user_editable because it has a content_editable attribute set
25 26 27 |
# File 'lib/watir/user_editable.rb', line 25 def content_editable defined?(@content_editable) && content_editable? end |
#set(*args) ⇒ Object Also known as: value=
Clear the element, then type in the given value.
11 12 13 14 15 16 |
# File 'lib/watir/user_editable.rb', line 11 def set(*args) element_call(:wait_for_writable) do @element.clear @element.send_keys(*args) end end |
#set!(*args) ⇒ Object
Uses JavaScript to enter most of the given value. Selenium is used to enter the first and last characters This might provide a performance improvement when entering a lot of text on a local machine
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/watir/user_editable.rb', line 37 def set!(*args) msg = '#set! does not support special keys, use #set instead' raise ArgumentError, msg if args.any?(::Symbol) input_value = args.join set input_value[0] return content_editable_set!(*args) if content_editable element_call { execute_js(:setValue, @element, input_value[0..-2]) } append(input_value[-1]) return if value == input_value raise Exception::Error, "#set! value: '#{value}' does not match expected input: '#{input_value}'" end |