【问题标题】:Michael Hartl's Rails Tutorial, 7.3 Capybara::ElementNotFoundMichael Hartl 的 Rails 教程,7.3 Capybara::ElementNotFound
【发布时间】:2013-05-23 20:17:48
【问题描述】:

我在 Hartl's Rails 教程的 Section 7.3.1 中,遇到以下错误:

Capybara::ElementNotFound:
   no button with value or id or text 'Create my account' found

但据我所知,具有该值的按钮确实存在。

这是 new.html.erb 代码:

<div class="row">
    <div class="span6 offset3">
        <%= form_for(@user) do |f| %>



            <%= f.label :name %>
            <%= f.text_field :name %>

            <%= f.label :email %>
            <%= f.text_field :email %>

            <%= f.label :password %>
            <%= f.password_field :password %>

            <%= f.label :password_confirmation, "Confirmation" %>
            <%= f.password_field :password_confirmation %>

            <%= f.submit "Create my acccount", class: "btn btn-large btn-primary" %>
        <% end %>
    </div>
</div>

这里有人有什么想法吗?

另外,这是测试的一部分:

describe "signup" do

    before { visit signup_path }

    let(:submit) { "Create my account" }

    describe "with invalid information" do
      it "should not create a user" do
        expect { click_button submit }.not_to change(User, :count)
      end
    end

    describe "with valid information" do
      before do
        fill_in "Name",         with: "Example User"
        fill_in "Email",        with: "user@example.com"
        fill_in "Password",     with: "foobar"
        fill_in "Confirmation", with: "foobar"
      end

      it "should create a user" do
        expect { click_button submit }.to change(User, :count).by(1)
      end
    end
  end

“有效信息”和“无效信息”都失败了也可能一文不值。

【问题讨论】:

  • 帐户中多了一个“c”:&lt;%= f.submit "Create my acccount"。
  • 就是这样!谢谢你!现在我该如何投票?
  • 为 cmets 投票需要minimum reputation。

标签: ruby-on-rails-3.2 railstutorial.org


【解决方案1】:

我不知道您如何在 Capybara 中调用它,但尝试将 ID 添加到提交按钮并在 capybara 中通过 ID 调用。 根据文档,您应该调用click_button method。

【讨论】:

  • 我添加了一段测试文件,您可以在其中看到我调用 click_button 方法。
  • 看看launchy gem,安装gem并在访问signup_path后使用save_and_open_page方法。您可以在点击该 signup_path 后验证正在呈现的 HTML,以查看您的按钮是否确实正在呈现,或者即使注册路径将您带到正确的位置。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多