Using dom_id to localize testing.

I am trying to test a rails app using webrat. I have this sort of

  <table id="entities" caption="Entity Listing" ...>

      <th style="width:20em;">Short Name</th>
      <th colspan="2">Legal Name</th>


<% for entity in @entities %>
  <tr id="<%=dom_id(entity, :list)%>">
    <td><%=h entity.entity_name.titlecase -%></td>
    <td id="<%=dom_id(entity, :show)%>">
       <%= link_to 'Show Entity', entity -%></td>
    <td id="<%=dom_id(entity, :edit)%>">
       <%= link_to 'Edit Entity', edit_entity_path(entity) -%></td>
    <td id="<%=dom_id(entity, :delete)%>">
       <%= link_to 'Destroy Entity', entity,
                    :confirm => 'Are you sure?',
                    :method => :delete -%></td>

I am trying to test the destroy link using this webrat code:

  my_entity = Entity.find_by_entity_name(
    "my entity number #{row.hll_words_to_i}")
  within("body > table > tbody > tr#" + dom_id(my_entity, :list) +
         " > td#" + dom_id(my_entity, :delete)) do
    click_link "Destroy Entity"

This fails with a nil exception error:

      You have a nil object when you didn't expect it!
      The error occurred while evaluating nil.to_html (NoMethodError)

I have tried with other variants of the selector. If I check for the
selector using have_selector("td#" + dom_id(my_entity, :delete)) then it
passes. If I use the long form above it also passes. I test for a
missing selector then have_selector fails as expected. Therefore, I am
reasonably certain that the selector is indeed being found on the page.

Any ideas as to what I am doing wrong?