Sha256: 23491cb62928a6171069795eb7d825bc77b136ec3eab07637b9270bc72d2283a

Contents?: true

Size: 889 Bytes

Versions: 1

Compression:

Stored size: 889 Bytes

Contents

# encoding: utf-8
module Watir

  #
  # Represents an option in a select list.
  #

  class Option < HTMLElement

    #
    # Select this option
    #

    def select
      assert_exists

      # not sure why both is needed
      @element.click
      @element.select
    end

    #
    # Toggle the selected state of this option
    #

    def toggle
      assert_exists
      @element.toggle
    end

    #
    # Is this option selected?
    #

    def selected?
      assert_exists
      @element.selected?
    end

    def text
      assert_exists

      # 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
        @element.attribute(attribute)
      else
        @element.text
      end
    end

  end # Option
end # Watir

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
watir-webdriver-0.0.1.dev7 lib/watir-webdriver/elements/option.rb