Capybara::ElementNotFound:无法找到字段“标题"; [英] Capybara::ElementNotFound: Unable to find field "title"

查看:33
本文介绍了Capybara::ElementNotFound:无法找到字段“标题";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法解决此问题.请帮我.它给了我找不到元素的错误.

spec/features/todos/create_spec.rb

需要'spec_helper'描述创建待办事项"做let(:user) { FactoryGirl.create(:user)}之前(:每个)做访问 root_pathclick_link "登录"填写电子邮件",使用:user@gmail.com"填写密码",用:密码"click_button "登录"结尾它重定向到待办事项索引页面"做访问/todos"填写标题",带有:MyString"click_button创建"expect(page).to have_title("MyString")结尾

我的查看代码._new_form.html.erb

 <%= form_for current_user.todos.new, remote:true do |f|%><div class="input-group"><%= f.text_field :title, class: "form-control", placeholder: "title" %><span class="input-group-btn"><%= f.submit "Create", class: "btn btn-success" %></span>

<%结束%>

spec_helper.rb

 def sign_in@user = FactoryGirl.create(:user)controller.stub(:authenticate_user!).and_return(true)@用户结尾

解决方案

找到我的答案.

在视图文件中,我有一个带有 id 标题的 text_field.控制台中的 id = todo_title但是我在测试中调用 title .这里水豚没能找到标题.原来是 todo_title

使用后

fill_in "todo_title"

它很有魅力.

I could not resolve this issue. Please help me. It gives me element not found error.

spec/features/todos/create_spec.rb

require 'spec_helper'

describe "Creating todos" do

 let(:user) { FactoryGirl.create(:user)}
 before(:each) do
   visit root_path
   click_link "Login"

   fill_in "Email",  with:  "user@gmail.com"
   fill_in "Password",  with: "password"
   click_button "Sign in"
 end

  it "redirects to the todos index page" do
   visit "/todos"

   fill_in "title", with: "MyString"
   click_button "Create"

   expect(page).to have_title("MyString")
 end

my view code. _new_form.html.erb

     <%= form_for current_user.todos.new, remote:true  do |f| %>
       <div class="input-group">
         <%= f.text_field :title, class: "form-control",   placeholder: "title" %>
         <span class="input-group-btn">
         <%= f.submit "Create", class: "btn btn-success" %>
         </span>
       </div>
     <% end %>

spec_helper.rb

    def sign_in
      @user = FactoryGirl.create(:user)
      controller.stub(:authenticate_user!).and_return(true)
      @user
    end

解决方案

Found my answer.

In the view file I've a text_field with title with an id. The id = todo_title in the console But am calling title in the test . Here the capybara not been able to find title. It was todo_title

After using

fill_in "todo_title"

It worked like charm.

这篇关于Capybara::ElementNotFound:无法找到字段“标题";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆