Sha256: dca40d3aa872c08526704712111074ad90b9136e1b11e61a37210761816355e6

Contents?: true

Size: 1.5 KB

Versions: 2

Compression:

Stored size: 1.5 KB

Contents

module PageObject
  module Elements
    class SelectList < Element

      #
      # Return the PageObject::Elements::Option for the index provided.  Index
      # is zero based.
      #
      # @return [PageObject::Elements::Option]
      #
      def [](idx)
        options[idx]
      end

      #
      # Return an array of Options contained in the select list.
      #
      # @return [array of PageObject::Elements::Option]
      #
      def options
        element.options.map { |e| ::PageObject::Elements::Option.new(e, :platform => :watir) }
      end

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

      #
      # @return [Array<String>] An array of strings representing the value of the currently selected options.
      #
      def selected_values
        element.selected_options.map { |e| e.value }.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

      protected

      def child_xpath
        ".//child::option"
      end

      def self.watir_finders
        super + [:text, :value, :label]
      end

    end

    ::PageObject::Elements.tag_to_class[:select] = ::PageObject::Elements::SelectList
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
page-object-2.1.1 lib/page-object/elements/select_list.rb
page-object-2.1 lib/page-object/elements/select_list.rb