# Capybara using Xpath to ensure there is no elements

Posted by ZedTuX 0n R00t on October 17, 2014

Let’s say you are in the case where you’d like to ensure an element has no child within your test running with Capybara.

You can perform this easily thanks to the have_xpath methods options:

1
expect(page).to have_xpath('//div[@id="list"]/a', count: 0)


This will raise an exception in the case the div with the id list has some a elements.