English 中文(简体)
元素不值 :
原标题:Capybara::ElementNotFound:

我正在测试我的铁路应用程序 与Rspec和Capybara的签名表格。 当我想要测试它时,我面对这个错误,

Failures:

  1) user registration allows new users to register with an email address and password
     Failure/Error: fill_in "Confirmation",          :with => "foo"
     Capybara::ElementNotFound:
       no text field, text area or password field with id, name, or label  Confirmation  found
     # ./user_spec.rb:9:in `block (2 levels) in <top (required)> 

这是我的表格 是一种签名表格

<div id="box">
  <div class="block" id="block-signup">
    <h2>Sign up</h2>
    <div class="content">
      <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :class => "form login"}) do |f| %>
          <% if @user.errors.any? %>
              <div id="errorExplanation">
                <h2><%= pluralize(@user.errors.count, "error") %> prohibited
                  this post from being saved:</h2>
                <ul>
                  <% @user.errors.full_messages.each do |msg| %>
                      <li><%= msg %></li>
                  <% end %>
                </ul>
              </div>
              <%end%>
        <div class="group wat-cf">
          <div class="left">
            <label class="label"><%= f.label :email %></label>
          </div>
          <div class="right">
            <%= f.email_field :email %>
            <span class="description">Ex: [email protected]</span>
          </div>
        </div>
        <div class="group wat-cf">
          <div class="left">
            <label class="label"><%= f.label :password %></label>
          </div>
          <div class="right">
            <%= f.password_field :password %>
            <span class="description">Must contains the word  yeah </span>
          </div>
        </div>
        <div class="group wat-cf">
          <div class="left">
            <label class="label"><%= f.label :confirmation %></label>
          </div>
          <div class="right">
            <%= f.password_field :password_confirmation %>
            <span class="description">Don t miss any letters</span>
          </div>
        </div>

        <div class="group navform wat-cf">
          <button class="button" type="submit">
            <%= f.submit "Sign in", :type => :image, :src => "http://pilu.github.com/web-app-theme/images/icons/tick.png" %>
          </button>
        </div>
      <% end %>
    </div>
    <div id="links-sup">
      <h4><%= render "links" %></h4></div>
  </div>
</div>

我的测试文件是 pepe/ respe/ user_ pec. rb

require  spec_helper 

describe "user registration" do
  it "allows new users to register with an email address and password" do
    visit "/users/sign_up"

    fill_in "Email",                 :with => "[email protected] "
    fill_in "Password",              :with => "foo"
    fill_in "Confirmation",          :with => "foo"

    click_button "Sign up"

    page.should have_content("Welcome! You have signed up successfully.")
  end
end

你有办法解决吗?

最佳回答

这里的错误表明它找不到标签为“ 确认”的文本框。 您在这里对 html 有问题。 有 < strong> > no textbox 标签为 < / strong > 。 您可以点击标签“ 确认” 来测试光标不会在 < code > password_ confirmation textbox 中 。

查看为什么单击“ 密码” 标签, 光标在密码文本框中。 这就是为什么 < code> password 字段没有错误 。

您可以略微将标记修改为 f. label:password_ confirmation

当您看到错误 < code> Capybara :: EplenotFound 时,它只是表示无法找到您引用的元素。 因此您需要检查您的标记是正确的 。

问题回答

暂无回答




相关问题
Remove ActiveRecord in Rails 3

Now that Rails 3 beta is out, I thought I d have a look at rewriting an app I have just started work on in Rails 3 beta, both to get a feel for it and get a bit of a head-start. The app uses MongoDB ...

When will you upgrade your app to Rails 3? [closed]

Now that the Rails 3 beta is here, let s take a little straw poll. Please tell us briefly what your application does and when you will upgrade it to Rails 3. Or, if you re not planning on upgrading ...

Bundler isn t loading gems

I have been having a problem with using Bundler and being able to access my gems without having to require them somewhere, as config.gem used to do that for me (as far as I know). In my Rails 3 app, I ...

bypass attr_accessible/protected in rails

I have a model that, when it instantiates an object, also creates another object with the same user id. class Foo > ActiveRecord::Base after_create: create_bar private def create_bar Bar....

concat two fields activerecord

I m so used to oracle where you can simply concat(field1, , field2) but if I m using activerecord to find the field1 and field2, and I need a space in between, how do I accomplish this? Cheers ...

热门标签