title: How to find the nth element that has a class of .foo in the document with Capybara/Nokogiri
body: <p>I'm trying to find the n-th element that has a special class in a document. The elements are not necessarily children of the same parent. So for example</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;ul&gt;
    &lt;li&gt;&lt;div class="foo"&gt;This&lt;/div&gt;&lt;/li&gt;
    &lt;li&gt;&lt;div&gt;Nothing&lt;/div&gt;
      &lt;ul&gt;
        &lt;li&gt;&lt;div class="foo"&gt;This also&lt;/div&gt;&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;div class="foo"&gt;And this&lt;/div&gt;&lt;li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>I'd like to find the first, second or third element that has the class <code>.foo</code>.</p>
  
  <p>I tried</p>
  
  <pre class="lang-ruby prettyprint-override"><code>page.find '.foo'
  </code></pre>
  
  <p>Which errors in <code>Capybara::Ambiguous: Ambiguous match, found 3 elements matching css ".foo"</code></p>
  
  <p>I then tried</p>
  
  <pre class="lang-ruby prettyprint-override"><code>page.all('.foo')[n]
  </code></pre>
  
  <p>Which works nice except that it doesn't seem to wait this little time like Capybaras <code>find</code> does, which I need because the HTML is actually generated from ajax data. So how to do this correctly with find?</p>