class Selenium::WebDriver::Support::Select

def find_by_text(text)

def find_by_text(text)
  xpath = ".//option[normalize-space(.) = #{Escaper.escape text}]"
  opts = @element.find_elements(xpath: xpath)
  return opts unless opts.empty? && /\s+/.match?(text)
  longest_word = text.split(/\s+/).max_by(&:length)
  if longest_word.empty?
    candidates = options
  else
    xpath = ".//option[contains(., #{Escaper.escape longest_word})]"
    candidates = @element.find_elements(xpath: xpath)
  end
  return Array(candidates.find { |option| text == option.text }) unless multiple?
  candidates.select { |option| text == option.text }
end