Sha256: 9394e4383039c43c8d5b26e252b8591a063c276475b0999bbbf3d7af8bc2bf82

Contents?: true

Size: 1.94 KB

Versions: 5

Compression:

Stored size: 1.94 KB

Contents

module PageObject
  module Platforms
    module WatirWebDriver
      module SelectList

        #
        # Return the PageObject::Elements::Option for the index provided.  Index
        # is zero based.
        #
        # @return [PageObject::Elements::Option]
        #
        def [](idx)
          Object::PageObject::Elements::Option.new(options[idx], :platform => :watir_webdriver)
        end

        #
        # Select a value from the list
        #
        def select(value)
          element.select(value)
        end

        #
        # Select the option(s) whose value attribute matches the given
        # string
        #
        def select_value(value)
          element.select_value(value)
        end

        #
        # Return an array of Options contained in the select lit.
        #
        # @return [array of PageObject::Elements::Option]
        #
        def options
          elements = []
          options = element.wd.find_elements(:xpath, child_xpath)
          options.each do |opt|
            elements << Object::PageObject::Elements::Option.new(opt, :platform => :watir_webdriver)
          end
          elements
        end

        #
        # @return [Array<String>] An array of strings representing the text value of the currently selected options.
        #
        def selected_options
          element.selected_options.map { |e| e.text }.compact
        end

        #
        # Returns true if the select list has one or more options where text or label matches the given value.
        #
        # @param [String, Regexp] value A value.
        # @return [Boolean]
        def include?(value)
          element.include? value
        end
        
        #
        # Returns true if any of the selected options' text or label match the given value.
        #
        # @param [String, Regexp] value A value.
        # @return [Boolean]
        def selected?(value)
          element.selected? value
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
page-object-0.7.3 lib/page-object/platforms/watir_webdriver/select_list.rb
page-object-0.7.2 lib/page-object/platforms/watir_webdriver/select_list.rb
page-object-0.7.1 lib/page-object/platforms/watir_webdriver/select_list.rb
page-object-0.7.0 lib/page-object/platforms/watir_webdriver/select_list.rb
page-object-0.6.9 lib/page-object/platforms/watir_webdriver/select_list.rb