I’m having trouble getting capybara’s find method to locate what (I think) I know is on the page:
Spec snippet
scenario "edits an existing entry" do
visit "/manage"
click_on 'View Featured Companies'
expect(page).to have_content 'Featured Company'
expect(page).to have_content 'Featured News Article'
expect(page).to_not have_content "No Featured Companies"
expect(page).to_not have_content 'Edit Featured Company'
save_and_open_page
find('td').find('a[href*="edit"]').click
I’ve also tried
find('a[href$="edit"]')
and several other variations withe the same result or with a “Can’t find it” error message
HTML snippet from save_and_open_page
<td>
<a href="/manage/featured_companies/1/edit"><img alt="Icn_edit" src="/manage/images/icn_edit.png" title="Edit" /></a>
<a href="/manage/featured_companies/1" data-confirm="Are you sure? This is permanent." data-method="delete" rel="nofollow"><img alt="Icn_trash" src="/manage/images/icn_trash.png" title="Destroy" /></a>
RSpec failure message
FeaturedCompanies
edits an existing entry (FAILED - 1)
Failures:
1) FeaturedCompanies edits an existing entry
Failure/Error: save_and_open_page
NoMethodError:
undefined method `-@' for #<Thread:0x00000004ac0428 sleep>
# ./spec/features/edit_featured_companies_spec.rb:29:in `block (2 levels) in <top (required)>'
Edit. I found this error; there was an extra ‘-’ on one line
OR this if I remove the save_and_open_page
1) FeaturedCompanies edits an existing entry
Failure/Error: find('td').find('a[href*="edit"]').click
Capybara::ElementNotFound:
Unable to find css "a[href*=\"edit\"]"
# ./spec/features/edit_featured_companies_spec.rb:30:in `block (2 levels) in <top (required)>'
Edit. Have to use the following:
within('tablesorter') do
find('a[href=$="edit"]').click
end
Getting a “Can’t find it” error message was strange enough, but what is this thing about a ‘-@’ method mean?