Sha256: 9cd0d8fd1c401153b132604db1fd3f5b1b1e27775be3757fcb5581a5cda88117

Contents?: true

Size: 1.31 KB

Versions: 11

Compression:

Stored size: 1.31 KB

Contents

module Watir

  #
  # Represents an option in a select list.
  #

  class Option < HTMLElement

    #
    # Selects this option.
    #
    # @example
    #   browser.select(id: "foo").options.first.select
    #

    alias_method :select, :click

    #
    # Toggles the selected state of this option.
    #
    # @example
    #   browser.select(id: "foo").options.first.toggle
    #

    alias_method :toggle, :click

    #
    # Clears (i.e. toggles selected state) option.
    #
    # @example
    #   browser.select(id: "foo").options.first.clear
    #

    def clear
      click if selected?
    end

    #
    # Is this option selected?
    #
    # @return [Boolean]
    #

    def selected?
      assert_exists
      element_call { @element.selected? }
    end

    #
    # Returns the text of option.
    #
    # Note that the text is either one of the following respectively:
    #   * label attribute
    #   * text attribute
    #   * inner element text
    #
    # @return [String]
    #

    def text
      # A little unintuitive - we'll return the 'label' or 'text' attribute if
      # they exist, otherwise the inner text of the element

      attribute = [:label, :text].find { |a| attribute? a }

      if attribute
        attribute_value(attribute)
      else
        super
      end
    end

  end # Option
end # Watir

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
watir-webdriver-0.9.9 lib/watir-webdriver/elements/option.rb
watir-6.0.0.beta5 lib/watir/elements/option.rb
watir-6.0.0.beta4 lib/watir/elements/option.rb
watir-6.0.0.beta3 lib/watir/elements/option.rb
watir-6.0.0.beta2 lib/watir/elements/option.rb
watir-6.0.0.beta1 lib/watir/elements/option.rb
watir-webdriver-0.9.3 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.9.2 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.9.1 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.9.0 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.8.0 lib/watir-webdriver/elements/option.rb