Capybara :: ElementNotFound: Unable to find xpath "/ html"

I follow the Ruby on Rails tutorial at http://ruby.railstutorial.org/chapters/static-pages and stumbled upon the following error

 StaticPages Home page should have the content 'Sample App'
 Failure/Error: page.should have_content('Sample App')
 Capybara::ElementNotFound:
   Unable to find xpath "/html"
 # (eval):2:in `text'
 # ./spec/requests/static_pages_spec.rb:7:in `(root)'

My gem file is as follows

source 'http://rubygems.org'

gem 'rails', '3.0.10'

gem 'jruby-openssl'

gem 'activerecord-jdbcsqlite3-adapter'
group :development, :test do
   gem 'webrat'
   gem 'rspec-rails', ">= 2.10.0"
   gem 'capybara', ">= 1.1.2"
end

How do I get rid of this error and pass rspec? Original file

require 'spec_helper'

describe "StaticPages" do

  describe "Home page" do

    it "should have the content 'Sample App'" do
      visit '/static_pages/home'
      # puts page.html
      page.should have_content('Sample App')
    end
  end
end
+5
source share
4 answers

Perhaps the problem is with the Webrat gem + capybara gem, try removing webrat from your gemfile.

check this problem

+4
source

You may have a bug that prevents the page from rendering correctly.

Use some debugging tools for reference:

  • puts page.html .
  • (log/test.log)

./spec/requests/static_pages_spec.rb?

+3

, :

visit '/static_pages/home'

"-", . , "home", :

home_path

, config/routes.rb.

+2

Today I had the same error, but with a different case. I included include Capybara::DSLin spec_helper.rb( rails_helper.rb).

Then, when I run the spec, a warning quietly appears including Capybara::DSL in the global scope is not recommended!. but in some tests I got it Capybara::ElementNotFound: Unable to find xpath "/html".

I had to include in the block RSpec.configure.

RSpec.configure do |config|
  config.include Capybara::DSL
end
0
source

All Articles