Sha256: 446438eec3fa96b10ef78eae35afb5386bdf1769105a22ed3a2c9015bb61bece

Contents?: true

Size: 1.26 KB

Versions: 23

Compression:

Stored size: 1.26 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?
      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

      [:label, :text].each do |a|
        val = attribute_value(a)
        return val unless val.nil?
      end

      super
    end

  end # Option
end # Watir

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
watir-6.13.0 lib/watir/elements/option.rb
watir-6.12.0 lib/watir/elements/option.rb
watir-6.11.0 lib/watir/elements/option.rb
watir-6.11.0.beta2 lib/watir/elements/option.rb
watir-6.11.0.beta1 lib/watir/elements/option.rb
watir-6.10.3 lib/watir/elements/option.rb
watir-6.10.2 lib/watir/elements/option.rb
watir-6.10.0 lib/watir/elements/option.rb
watir-6.9.1 lib/watir/elements/option.rb
watir-6.9.0 lib/watir/elements/option.rb
watir-6.8.4 lib/watir/elements/option.rb
watir-6.8.3 lib/watir/elements/option.rb
watir-6.8.2 lib/watir/elements/option.rb
watir-6.8.1 lib/watir/elements/option.rb
watir-6.8.0 lib/watir/elements/option.rb
watir-6.7.3 lib/watir/elements/option.rb
watir-6.7.2 lib/watir/elements/option.rb
watir-6.7.1 lib/watir/elements/option.rb
watir-6.7.0 lib/watir/elements/option.rb
watir-6.6.3 lib/watir/elements/option.rb