Capybara/RSpec 'have_css' matcher not working but has_css does

不羁岁月 提交于 2019-12-05 01:13:58

By default, Capybara only looks for "visible" elements. The head element (and its title element) are not really considered visible. This results in the title element being ignored in have_css.

You can force Capybara to also consider non-visible elements by the :visible => false option.

expect(page).to have_css('title', :text => 'Todo', :visible => false)

However, it would be easier to use the have_title method:

expect(page).to have_title('Todo')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!