Sha256: 64ee2982d9cffe84ff1af789c1aab6fa2b88908553bce5430feef64d8d84e471

Contents?: true

Size: 990 Bytes

Versions: 4

Compression:

Stored size: 990 Bytes

Contents

# frozen_string_literal: true

module Watir
  #
  # Represents an option in a select list.
  #

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

    alias select click

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

    alias 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.
    #
    # getAttribute atom pulls the text value if the label does not exist
    #
    # @return [String]
    #

    def text
      attribute_value(:label)
    end
  end # Option
end # Watir

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
watir-7.3.0 lib/watir/elements/option.rb
watir-7.2.2 lib/watir/elements/option.rb
watir-7.2.1 lib/watir/elements/option.rb
watir-7.2.0 lib/watir/elements/option.rb