title: How to test a Select2 element with capybara DSL?
body: <p>I have a <a href="http://ivaynberg.github.com/select2/" rel="noreferrer">Select2</a> element on a page that loads results via ajax. Would like to test this with capybara/rspec (using the poltergeist driver), but since the Select2 element actually starts out as a hidden field, and then populates a <code>&lt;ul&gt;</code> once results are processed, none of the normal <code>select</code>, <code>fill_in</code> or <code>choose</code> helpers will work.</p>
  
  <p>What I have now is something like</p>
  
  <pre><code>  it "should have a search field for events" do
      click_link "Select an Event"       # this works as expected
      within('.select2-container') do    # works
        find('.select2-search input').set(event.description[0,5])  # won't work!
        find(:xpath, "li[text()='#{event.description}']").click 
      end
      click_button "Search"
      page.should have_content("Displaying all 2 photos")
    end
  </code></pre>
  
  <p>line 4 above, apparently capybara can find the element but the value isn't changed and Select2 never makes its ajax call. (can't use normal <code>fill_in</code> there because the search field element has no label, id, or name attributes)</p>