module Watir::UserEditable
Public Instance Methods
append(*args)
click to toggle source
Appends the given value to the text in the text field.
@param [String, Symbol] args
# File lib/watir/user_editable.rb, line 49 def append(*args) raise NotImplementedError, '#append method is not supported with contenteditable element' if content_editable send_keys(*args) end
Also aliased as: <<
clear()
click to toggle source
Clears the text field.
# File lib/watir/user_editable.rb, line 60 def clear element_call(:wait_for_writable) do @element.clear end end
content_editable()
click to toggle source
Uses JavaScript to enter most of the given value. Selenium is used to enter the first and last characters
@param [String, Symbol] args
# File lib/watir/user_editable.rb, line 24 def content_editable defined?(@content_editable) && content_editable? end
set(*args)
click to toggle source
Clear the element, then type in the given value.
@param [String, Symbol] args
# File lib/watir/user_editable.rb, line 9 def set(*args) element_call(:wait_for_writable) do @element.clear @element.send_keys(*args) end end
Also aliased as: value=
set!(*args)
click to toggle source
# File lib/watir/user_editable.rb, line 28 def set!(*args) msg = '#set! does not support special keys, use #set instead' raise ArgumentError, msg if args.any? { |v| v.is_a?(::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
Private Instance Methods
content_editable_set!(*args)
click to toggle source
# File lib/watir/user_editable.rb, line 68 def content_editable_set!(*args) input_text = args.join element_call { execute_js(:setText, @element, input_text) } return if text == input_text raise Exception::Error, "#set! text: '#{text}' does not match expected input: '#{input_text}'" end