Sha256: 880ebd7562c44f607081aad03f42f6926b696d39b083e7c80a8d8ceec7885045

Contents?: true

Size: 1.25 KB

Versions: 5

Compression:

Stored size: 1.25 KB

Contents

module Watir
  module UserEditable

    #
    # Clear the element, then type in the given value.
    #
    # @param [String, Symbol] args
    #

    def set(*args)
      element_call(:wait_for_writable) do
        @element.clear
        @element.send_keys(*args)
      end
    end
    alias_method :value=, :set

    #
    # Uses JavaScript to enter most of the given value.
    # Selenium is used to enter the first and last characters
    #
    # @param [String] input_value
    #

    def set!(*args)
      raise ArgumentError, "#set! does not support special keys, use #set instead" if args.any? { |v| v.kind_of?(::Symbol) }
      input_value = args.join
      set input_value[0]
      element_call { execute_js(:setValue, @element, input_value[0..-2]) }
      append(input_value[-1])
      raise Watir::Exception::Error, "#set! value does not match expected input" unless value == input_value
    end

    #
    # Appends the given value to the text in the text field.
    #
    # @param [String, Symbol] args
    #

    def append(*args)
      send_keys(*args)
    end
    alias_method :<<, :append

    #
    # Clears the text field.
    #

    def clear
      element_call(:wait_for_writable) do
        @element.clear
      end
    end

  end # UserEditable
end # Watir

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
watir-6.12.0 lib/watir/user_editable.rb
watir-6.11.0 lib/watir/user_editable.rb
watir-6.11.0.beta2 lib/watir/user_editable.rb
watir-6.11.0.beta1 lib/watir/user_editable.rb
watir-6.10.3 lib/watir/user_editable.rb