Sha256: d4a7269da908731e400015d3a8293f15c7911fcb464a67686be0206604cb3c14

Contents?: true

Size: 1.89 KB

Versions: 11

Compression:

Stored size: 1.89 KB

Contents

# encoding: utf-8
module Watir
  class TextField < Input

    attributes Watir::TextArea.typed_attributes
    remove_method :type # we want Input#type here, which was overriden by TextArea's attributes

    def self.from(parent, element)
      type = element.attribute(:type)

      if TextFieldLocator::NON_TEXT_TYPES.include?(type)
        raise TypeError, "expected type != #{type} for #{element.inspect}"
      end

      super
    end

    #
    # Clear the element, the type in the given value.
    #

    def set(*args)
      assert_exists
      assert_writable

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

    #
    # Append the given value to the text in the text field.
    #

    def append(*args)
      assert_exists
      assert_writable

      @element.send_keys(*args)
    end

    #
    # Clear the text field.
    #

    def clear
      assert_exists
      @element.clear
    end

    #
    # Returns the text in the text field.
    #

    def value
      # since 'value' is an attribute on input fields, we override this here
      assert_exists
      @element.value
    end

    private

    def locate
      @parent.assert_exists
      TextFieldLocator.new(@parent.wd, @selector, self.class.attribute_list).locate
    end

    def selector_string
      selector = @selector.dup
      selector[:type] = '(any text type)'
      selector[:tag_name] = "input or textarea"
      selector.inspect
    end
  end

  module Container
    def text_field(*args)
      TextField.new(self, extract_selector(args).merge(:tag_name => "input"))
    end

    def text_fields(*args)
      TextFieldCollection.new(self, extract_selector(args).merge(:tag_name => "input"))
    end
  end # Container

  class TextFieldCollection < InputCollection
    private

    def locator_class
      TextFieldLocator
    end

    def element_class
      TextField
    end
  end # TextFieldCollection
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
watir-webdriver-0.1.7 lib/watir-webdriver/elements/text_field.rb
watir-webdriver-0.1.6 lib/watir-webdriver/elements/text_field.rb
watir-webdriver-0.1.5 lib/watir-webdriver/elements/text_field.rb
watir-webdriver-0.1.4 lib/watir-webdriver/elements/text_field.rb
watir-webdriver-0.1.3 lib/watir-webdriver/elements/text_field.rb
watir-webdriver-0.1.2 lib/watir-webdriver/elements/text_field.rb
ayanko-watir-webdriver-0.1.1.1 lib/watir-webdriver/elements/text_field.rb
watir-webdriver-0.1.1 lib/watir-webdriver/elements/text_field.rb
watir-webdriver-0.1.0 lib/watir-webdriver/elements/text_field.rb
watir-webdriver-0.0.9 lib/watir-webdriver/elements/text_field.rb
watir-webdriver-0.0.8 lib/watir-webdriver/elements/text_field.rb