Topic: Element exists but Capybara says: not found on page?

How do I go about debugging this kind of problem?

I have the following feature which is failing on the indicated line. What makes this odd is that I know the element exists because I have tested the steps in my browser (without error).

# feature
Feature: Submit an inquiry
  In order to contact the website owner
  As a person who is viewing the portfolio
  I want send an inquiry

  @wip
  Scenario: Submitting an inquiry
    Given I am on the new inquiry page
    When I fill in "Name" with "Tim Cooper"
      And I fill in "Business Name" with "ACME Inc"
      And I fill in "Website" with "http://www.google.com/"
      And I fill in "Body" with "The website guru REALLY\n\nNeeds to read this!"
      And I press "Submit Inquiry"
    Then I should see "Thanks for your inquiry" within "#flash-messages" #this line is failing
      And I should be on the home page  

# controller
class InquiriesController < ApplicationController
  respond_to :html
  
  def new
    @inquiry = Inquiry.new
  end
  
  def create
    @inquiry = Inquiry.new params[:inquiry]
    @inquiry.user_agent = request.user_agent
    @inquiry.ip = request.remote_ip
    @inquiry.state = 'new'
    add_notice "Thanks for your inquiry." if @inquiry.save
    respond_with @inquiry, :location => root_path
  end
end

# app.html.erb (just the required part)
<section id="content">
    <%= render_flash_messages('flash-messages') %>
    <%= yield %>
</section>

# Stack trace
Feature: Submit an inquiry
  In order to contact the website owner
  As a person who is viewing the portfolio
  I want send an inquiry

  @wip
  Scenario: Submitting an inquiry                                              # features/public/submit_inquiry.feature:7
    Given I am on the new inquiry page                                         # features/step_definitions/web_steps.rb:19
    When I fill in "Name" with "Tim Cooper"                                    # features/step_definitions/web_steps.rb:39
    And I fill in "Business Name" with "ACME Inc"                              # features/step_definitions/web_steps.rb:39
    And I fill in "Website" with "http://www.google.com/"                      # features/step_definitions/web_steps.rb:39
    And I fill in "Body" with "The website guru REALLY\n\nNeeds to read this!" # features/step_definitions/web_steps.rb:39
    And I press "Submit Inquiry"                                               # features/step_definitions/web_steps.rb:27
    Then I should see "Thanks for your inquiry" within "#flash-messages"       # features/step_definitions/web_steps.rb:107
      scope '//*[@id = 'flash-messages']' not found on page (Capybara::ElementNotFound)
      ./features/step_definitions/web_steps.rb:14:in `with_scope'
      ./features/step_definitions/web_steps.rb:108:in `/^(?:|I )should see "([^\"]*)"(?: within "([^\"]*)")?$/'
      features/public/submit_inquiry.feature:14:in `Then I should see "Thanks for your inquiry" within "#flash-messages"'

Failing Scenarios:
cucumber -p wip features/public/submit_inquiry.feature:7 # Scenario: Submitting an inquiry

1 scenario (1 failed)
7 steps (1 failed, 6 passed)
0m0.075s

The --wip switch was used, so the failures were expected. All is good.

Thanks

Re: Element exists but Capybara says: not found on page?

To see what Cucumber is seeing, add this before the failing step:

Then show me the page

Re: Element exists but Capybara says: not found on page?

Thanks for suggesting this - it is something that I tried and the page came back sans flash (it was also missing the database entries) so I guessed that the "Then show me the page" step doesn't return everything...

As I said in my previous post I have confirmed that the flash message shows up by manually submitting and entry. Has anyone come across a similar issue?

Re: Element exists but Capybara says: not found on page?

This ended up being my issue (perks of learning). Cucumber was just doing as it was told.