jnicklas/capybara — Issue #651: Failure/Error: click_button "Send" Capybara::ElementNotFound: no button with value or id or text 'Send' found
Author: jmflannery
Created: 2012-02-29 09:04:56+00:00
State: open

Hi

Recently, when I use the latest Capybara gem from github in my Rails 3.2.0 app:

gem 'capybara', :git => 'https://github.com/jnicklas/capybara.git'
or
gem 'capybara', :git => 'git://github.com/jnicklas/capybara.git'

and I run the following test:

before(:each) do
@user = Factory(:user)
@message = "this is a message"
end

it "should show the message on the senders screen", :js => true do
visit signin_path
fill_in "Name", :with => @user.name
fill_in "Password", :with => @user.password
click_button "Sign In"
fill_in "message_content", :with => @message
click_button "Send"
page.should have_content("#{@user.name}: #{@message}")
end

the test fails with the error:

Failure/Error: click_button "Send" Capybara::ElementNotFound: no button with value or id or text 'Send' found

However, if I change my Gemfile to use Capybara 1.1.2:

gem 'capybara', "~> 1.1.2"

and run the test again with no other modifications to the app, the Send button is found and the test passes. And until recently, this test used to pass when using the latest capybara gem from github.

Notice that click_button is called twice from the test on two different buttons. The first button is found by capybara, but the second button is not found.

The HTML that contains the Send button, which capybara cannot find, is:

However, I found that while using the latest capybara gem, if I add an id attribute to the button html:

<%= f.submit "Send", id: "Send" %>

and then replace:

click_button "Send"

with

find('input#Send').click

with no other modifications to the app, capybara finds the button and the test then passes.

But I am wondering why click_button “Send” is not working any more. Perhaps I am over looking something or got something messed up.

I am using MRI Ruby 1.9.3p125. Some of my gems my app uses are:

Using rails (3.2.0)
Using rack (1.4.1)
Using rack-test (0.6.1)
Using rspec (2.8.0)
Using rspec-rails (2.8.1)

Thank you!

Jack Flannery