title: How do I rescue a Capybara Error Twice?
body: <p>I'm using Capybara to check a page for an element and return it's content.  If the element doesn't exist i'd like to look for a different element's content and return that.  If neither are found i'd like to return an empty string.</p>
  
  <p>The challenge here is that Capybara throws a <code>Capybara::ElementNotFound</code> error when <code>#find</code> fails. </p>
  
  <p>For selecting when the case is "return the element or an empty string" this is easy -- i simply <code>rescue</code> and return the empty string like below:</p>
  
  <pre><code>def select_post_meta_name(page)
    selector = 'div.post-name'
    page.find(selector).text
  rescue Capybara::ElementNotFound =&gt; e
    Rails.logger.warn('Could not get meta name: ' + e)
    ''
  end
  </code></pre>
  
  <p>How would i refactor the code above to handle something like the intent of the following pseudo code?</p>
  
  <pre><code># FAKE EMBARRASSING PSEUDO CODE ....
  def select_post_meta_name(page)
    selector = 'div.post-name'
    page.find(selector).text
  rescue Capybara::ElementNotFound =&gt; e
    other_element_selector = 'div.post-title'
    page.find(other_element_selector).text
  
    rescue Capybara::ElementNotFound =&gt; e
      Rails.logger.warn('Could not find any elements: ' + e)
      ''
  end
  # /FAKE EMBARRASSING PSEUDO CODE ....
  </code></pre>