Sha256: 78d3aa8450c0d14aa7ffa9e86e796c71d054de35d4378d83fa88bae06d333b98

Contents?: true

Size: 871 Bytes

Versions: 27

Compression:

Stored size: 871 Bytes

Contents

# encoding: utf-8
module Watir

  #
  # Represents an option in a select list.
  #

  class Option < HTMLElement

    #
    # Select this option
    #

    def select
      assert_exists

      @element.select
      fire_event("onclick") rescue nil
    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

27 entries across 27 versions & 2 rubygems

Version Path
watir-webdriver-0.2.4 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.2.3 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.2.2 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.2.1 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.2.0 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.2.0.dev2 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.2.0.dev lib/watir-webdriver/elements/option.rb
watir-webdriver-0.1.9 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.1.8 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.1.7 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.1.6 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.1.5 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.1.4 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.1.3 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.1.2 lib/watir-webdriver/elements/option.rb
ayanko-watir-webdriver-0.1.1.1 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.1.1 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.1.0 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.0.9 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.0.8 lib/watir-webdriver/elements/option.rb