lib/watir-classic/input_elements.rb in watir-classic-3.5.0 vs lib/watir-classic/input_elements.rb in watir-classic-3.6.0

- old
+ new

@@ -43,11 +43,11 @@ matching_items_in_select_list(:label, item) + matching_items_in_select_list(:value, item) raise NoValueFoundException, "No option with :text, :label or :value of #{item.inspect} in this select element" if matching_options.empty? matching_options.each(&:select) end - matching_options.first.text + first_present_option_value matching_options, :text end # Select an item or items in a select box by option's value. # # @param [String,Regexp] item option to select by value. @@ -56,11 +56,11 @@ # @macro enabled def select_value(item) matching_options = matching_items_in_select_list(:value, item) raise NoValueFoundException, "No option with :value of #{item.inspect} in this select element" if matching_options.empty? matching_options.each(&:select) - matching_options.first.value + first_present_option_value matching_options, :value end # @example Retrieve selected options as a text: # browser.select_list.selected_options.map(&:text) # @@ -97,9 +97,14 @@ opt.send(attribute) == value.to_s else raise TypeError, "#{value.inspect} can be only String, Regexp or Numeric!" end end + end + + def first_present_option_value(matching_options, field_to_return) + first_matching_option = matching_options.first + first_matching_option.present? ? first_matching_option.send(field_to_return) : "" end end # Returned by {Container#option}. class Option < Element