Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous match, found 2 elements matching css - Capybara

I have a test that renders two of the same elements on the page. I understand what the problem is with the error but I'm just not sure how to fix it? Here is my test:

TEST

 it "deletes the correct snitch" do
        user    = login_user
        snitch  = create(:snitch, :healthy, owner: user.accounts.first)
        snitch2 = create(:snitch, :healthy, owner: user.accounts.first)

        visit root_path
        delete = page.find(".icon-delete")
        first(delete).click
        expect(page).to have_content("Please confirm this delete.")


 end

ERROR

 Managing snitches deleting a snitch from the index page deletes the correct snitch
 Failure/Error: delete = page.find(".icon-delete")

 Capybara::Ambiguous:
   Ambiguous match, found 2 elements matching css ".icon-delete"

How can I pick just one of the icon delete on the page?

like image 582
Bitwise Avatar asked Oct 05 '16 13:10

Bitwise


1 Answers

click_on "Link Text.", match: :first
like image 106
Cristian Rennella Avatar answered Sep 22 '22 19:09

Cristian Rennella