Sha256: f82b0ee7678901b8010a1df72634a833cf4c4ff98a371a8672dcb2df4fe59853

Contents?: true

Size: 1.66 KB

Versions: 6

Compression:

Stored size: 1.66 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

    #
    # 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

6 entries across 6 versions & 1 rubygems

Version Path
watir-webdriver-0.2.1 lib/watir-webdriver/elements/text_field.rb
watir-webdriver-0.2.0 lib/watir-webdriver/elements/text_field.rb
watir-webdriver-0.2.0.dev2 lib/watir-webdriver/elements/text_field.rb
watir-webdriver-0.2.0.dev lib/watir-webdriver/elements/text_field.rb
watir-webdriver-0.1.9 lib/watir-webdriver/elements/text_field.rb
watir-webdriver-0.1.8 lib/watir-webdriver/elements/text_field.rb