Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm following the Ruby on Rails tutorial at http://ruby.railstutorial.org/chapters/static-pages and came across 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 the rspec? The source 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
like image 847
absessive Avatar asked May 15 '12 17:05

absessive


2 Answers

Maybe the problem is with webrat gem + capybara gem, try and remove webrat from your gemfile.

check this issue

like image 162
Coelhone Avatar answered Sep 19 '22 00:09

Coelhone


You may have an error that prevents the page from being rendered properly.

Use some debugging facilities for help :

  • Inside your request spec, use puts page.html to print the page content during your spec.
  • track the log files (log/test.log)

Could you show your ./spec/requests/static_pages_spec.rb source ?

like image 27
demental Avatar answered Sep 21 '22 00:09

demental