Vipin Verma
Vipin Verma

Reputation: 5736

Capybara: Check children of a div having class

I am trying to check if a div has a child with particular class in Capybara, using the following piece of code: expect(find("#admin-row-1 .glyphicon-ban-circle")).to_not be_empty

Upon debug, I get the following output

(byebug) find("#admin-row-1 .glyphicon-ban-circle")
#<Capybara::Node::Element tag="a" path="/html/body/main/div[2]/div/div/div/table/tbody/tr[3]/td[3]/a[2]">

But still, getting the following expectation error

Failure/Error: expect(find("#admin-row-1 .glyphicon-ban-circle")).to_not be_empty
       expected #<Capybara::Node::Element tag="a" path="/html/body/main/div[2]/div/div/div/table/tbody/tr[3]/td[3]/a[2]"> to respond to `empty?`

Upvotes: 4

Views: 3560

Answers (1)

Thomas Walpole
Thomas Walpole

Reputation: 49890

find returns an element or raises an exception, it doesn't return anything tha responds to empty?, You could use all instead which returns an array like object but a better solution is to use the have_css matcher provided by Capybara

expect(page).to have_css('#admin-row-1 .glyphicon-ban-circle')

Upvotes: 3

Related Questions