gpt4 book ai didi

ruby-on-rails - capybara ::ElementNotFound:找不到字段

转载 作者:行者123 更新时间:2023-11-28 21:27:05 25 4
gpt4 key购买 nike

我刚刚学习功能规范,但遇到了一个我不太明白的问题。 Capybara::ElementNotFound: 当我尝试运行测试时。这很奇怪,因为我逐字逐句地遵循模板,但我仍然收到此错误。我需要一些帮助!为了清楚起见,这是我的代码和错误。

测试

require "rails_helper"

RSpec.feature "Create a subscriber" do
scenario "Customer can sign up as a subscriber" do
visit "/subscribers/new"

user = User.create!(email: "user@example.com", password: "password")
fill_in "Email", with: "user@example.com"
fill_in "Password", with: "password"
click_button "Sign in"

fill_in "first_name", with:
fill_in "last_name", with:
fill_in "email", with:
fill_in "phone_number", with: "8269338"

expect(page).to have_content("Subscriber Has Been Successfully Created")
end
end

查看

  <%= form_for @subscriber do |form| %>
<div class="form-group">
<p>
<%= form.label :first %>
<%= form.text_field :first_name %>
</p>
<p>
<%= form.label :last %>
<%= form.text_field :last_name %>
</p>
<p>
<%= form.label :email %>
<%= form.text_field :email %>
</p>
<p>
<%= form.label :phone %>
<%= form.text_field :phone_number %>
</p>
</div>
<%= form.submit "Sign Up", class: "btn btn-primary" %>

错误 enter image description here

最佳答案

字段的 ID 都将以 subscriber_ 为前缀 - 尝试将 fill_in "first_name", with: "Cam" 更改为 fill_in "subscriber_first_name", with : "Cam" 看看是否能解决问题。

关于ruby-on-rails - capybara ::ElementNotFound:找不到字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37550827/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com