module Symbiont module WebObjects class SelectList < WebObject def initialize(web_object) @web_object = web_object end def self.usable_selectors super + [:value, :text, :label] end # This method is used to return an Option object based on the index provided. # @return [Symbiont::WebObjects::Option] def [](idx) ::Symbiont::WebObjects::Option.new(options[idx]) end # Selects an option from the select list. def select(value) web_object.select(value) end # Selects the option whose value attribute matches the provided string. def select_value(value) web_object.select_value(value) end # This method returns an array of Option objects that are contained within # a select list object. # @return [array of Symbiont::WebObjects::Option] def options web_objects = [] options = web_object.wd.find_elements(:xpath, option_xpath) options.each do |opt| web_objects << ::Symbiont::WebObjects::Option.new(opt) end web_objects end # This method returns an array of strings that contain the text of the # currently selected options in a select list. # @return [Array] def selected_options web_object.selected_options.map { |e| e.text }.compact end # This method returns an array of strings that contain the values of the # currently selected options in a select list. # @return [Array] def selected_values web_object.selected_options.map { |e| e.value }.compact end # This method returns true if any of the text or the label of any option # that is selected matches the provided value. # @param [String, Regexp] value A value to check for # @return [Boolean] def selected?(value) web_object.selected? value end # This method checks to see if the select list has one or more options # where the text or the label matches the provided value. # @param [String, Regexp] value A value to check for. # @return [Boolean] def include?(value) web_object.include? value end protected def option_xpath ".//child::option" end end # class: SelectList ::Symbiont::WebObjects.class_for_tag[:select] = ::Symbiont::WebObjects::SelectList end # module: WebObjects end # module: Symbiont