title: Rails + Cucumber/Selenium/Capybara: Compare the text values of two h4s with the same class?
body: <p>I have two <code>&lt;h4&gt;</code>s that surround the name of a search result. I need to compare the values of the first and last results to make sure that they are in alphabetical order. The h4's have a class of <code>search-result-name</code>. They are both in the same <code>form</code> tag with id <code>#search-results</code>.</p>
  
  <p>This is currently my broken cucumber test:</p>
  
  <pre><code>Then(/^the results should be alphabetical$/) do
    first_product_name = page.all('.search-result-name')[1] #first('.search-result-name').text
    last_product_name = page.all('.search-result-name')[2]
    first_product_name[0].should &lt;= last_product_name[0]
  end
  </code></pre>
  
  <p>This is giving me the error <code>undefined method '[]' for nil:NilClass (NoMethodError)</code>, so I'm thinking that I'm doing the find incorrectly. I can't find any documentation on how to find 2nd, 3rd, etc matches of an element. The thing is that they are both in the same div and they have the same class. How would I use selenium/capybara to look for it?</p>