Sha256: b29e6800e12b9e9980dfcab6844f12d8e945946498f1c117c64795d64ecae8c9

Contents?: true

Size: 829 Bytes

Versions: 17

Compression:

Stored size: 829 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.click
    end

    #
    # Toggle the selected state of this option
    #

    def toggle
      assert_exists
      @element.click
    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

17 entries across 17 versions & 1 rubygems

Version Path
watir-webdriver-0.4.1 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.4.0 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.3.9 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.3.8 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.3.7 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.3.6 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.3.5 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.3.4 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.3.3 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.3.2 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.3.1 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.3.0 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.2.9 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.2.8 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.2.7 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.2.6 lib/watir-webdriver/elements/option.rb
watir-webdriver-0.2.5 lib/watir-webdriver/elements/option.rb