lib/testcentricity_web/web_elements/select_list.rb
# Select the specified option in a select box object. Accepts a String or Hash.
# Supports standard HTML select objects and Chosen select objects.
#
# @param option [String] text of option to select
#             OR
# @param option [Hash] :value, :index, or :text of option to select
#
# @example
#   province_select.choose_option('Alberta')
#   province_select.choose_option(value: 'AB')
#   state_select.choose_option(index: 24)
#   state_select.choose_option(text: 'Maryland')
#
Select the specified option in a select box object. Accepts a String or Hash.
Supports standard HTML select objects and Chosen select objects.
Select the specified option in a select box object . Accepts a String or Hash . Supports standard HTML select objects and Chosen select objects .
def choose_option(option)
      @base_object, = find_element
      object_not_found_exception(@base_object, 'SelectList')
      trigger_list
      unless @options_list.nil?
        find_component(@options_list, 'drop menu')
        raise "Could not find option #{option} to choose" unless first(:css, @list_item, minimum: 0, wait: 5)
        if option.is_a?(Array)
          option.each do |item|
            page.find(:css, @list_item, text: item.strip).click
          end
        else
          if option.is_a?(Hash)
            @base_object.first(:css, "#{@list_item}:nth-of-type(#{option[:index]})").click if option.key?(:index)
            @base_object.first(:css, "#{@list_item}:nth-of-type(#{option[:value]})").click if option.key?(:value)
            @base_object.first(:css, "#{@list_item}:nth-of-type(#{option[:text]})").click if option.key?(:text)
          else
            options = @base_object.all(@list_item).collect(&:text)
            sleep(2) unless options.include?(option)
            first(:css, @list_item, text: option).click
          end
        end
        return
      end
      if first(:css, @list_item, minimum: 0, wait: 2)
        if option.is_a?(Array)
          option.each do |item|
            page.find(:css, @list_item, text: item.strip).click
          end
        else
          if option.is_a?(Hash)
            page.find(:css, "#{@list_item}:nth-of-type(#{option[:index]})").click if option.key?(:index)
            page.find(:css, "#{@list_item}:nth-of-type(#{option[:value]})").click if option.key?(:value)
            page.find(:css, "#{@list_item}:nth-of-type(#{option[:text]})").click if option.key?(:text)
          else
            options = @base_object.all(@list_item).collect(&:text)
            sleep(2) unless options.include?(option)
            first(:css, @list_item, text: option).click
          end
        end
      else
        if option.is_a?(Array)
          option.each do |item|
            select_item(@base_object, item)
          end
        else
          select_item(@base_object, option)
        end
      end
    end
def choose_option ( option ) @base_object , = find_element object_not_found_exception ( @base_object , 'SelectList' ) trigger_list unless @options_list . nil? find_component ( @options_list , 'drop menu' ) raise "Could not find option #{option} to choose" unless first ( :css , @list_item , minimum : 0 , wait : 5 ) if option . is_a? ( Array ) option . each do | item | page . find ( :css , @list_item , text : item . strip ) . click end else if option . is_a? ( Hash ) @base_object . first ( :css , "#{@list_item}:nth-of-type(#{option[:index]})" ) . click if option . key? ( :index ) @base_object . first ( :css , "#{@list_item}:nth-of-type(#{option[:value]})" ) . click if option . key? ( :value ) @base_object . first ( :css , "#{@list_item}:nth-of-type(#{option[:text]})" ) . click if option . key? ( :text ) else options = @base_object . all ( @list_item ) . collect ( & :text ) sleep ( 2 ) unless options . include? ( option ) first ( :css , @list_item , text : option ) . click end end return end if first ( :css , @list_item , minimum : 0 , wait : 2 ) if option . is_a? ( Array ) option . each do | item | page . find ( :css , @list_item , text : item . strip ) . click end else if option . is_a? ( Hash ) page . find ( :css , "#{@list_item}:nth-of-type(#{option[:index]})" ) . click if option . key? ( :index ) page . find ( :css , "#{@list_item}:nth-of-type(#{option[:value]})" ) . click if option . key? ( :value ) page . find ( :css , "#{@list_item}:nth-of-type(#{option[:text]})" ) . click if option . key? ( :text ) else options = @base_object . all ( @list_item ) . collect ( & :text ) sleep ( 2 ) unless options . include? ( option ) first ( :css , @list_item , text : option ) . click end end else if option . is_a? ( Array ) option . each do | item | select_item ( @base_object , item ) end else select_item ( @base_object , option ) end end end
Select the specified option in a select box object.
Select the specified option in a select box object .
option
:value, :index, or :text of option to select
: value : index or : text of option to select
example
province_select.choose_option('Alberta') province_select.choose_option(value: 'AB') state_select.choose_option(index: 24) state_select.choose_option(text: 'Maryland')
province_select . choose_option ( ' Alberta ' ) province_select . choose_option ( value : ' AB ' ) state_select . choose_option ( index : 24 ) state_select . choose_option ( text : ' Maryland ' )