Sha256: 811c8a3a198145ed3d4a713b18cd687e33911ff37e2ce7128e41083b3959e661

Contents?: true

Size: 1.29 KB

Versions: 15

Compression:

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

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

      if attribute
        attribute_value(attribute)
      else
        super
      end
    end

  end # Option
end # Watir

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
watir-6.5.0 lib/watir/elements/option.rb
watir-6.4.3 lib/watir/elements/option.rb
watir-6.4.2 lib/watir/elements/option.rb
watir-6.4.1 lib/watir/elements/option.rb
watir-6.4.0 lib/watir/elements/option.rb
watir-6.4.0.rc2 lib/watir/elements/option.rb
watir-6.4.0.rc1 lib/watir/elements/option.rb
watir-6.3.0 lib/watir/elements/option.rb
watir-6.2.1 lib/watir/elements/option.rb
watir-6.2.0 lib/watir/elements/option.rb
watir-6.1.0 lib/watir/elements/option.rb
watir-6.0.3 lib/watir/elements/option.rb
watir-6.0.2 lib/watir/elements/option.rb
watir-6.0.1 lib/watir/elements/option.rb
watir-6.0.0 lib/watir/elements/option.rb