如何解决 Capybara::ElementNotFound 错误

发布于 2024-09-17 16:38:58 字数 1673 浏览 2 评论 0原文

我遇到了以下问题,这是我第一次使用水豚,你知道我如何解决这个问题吗,谢谢

我使用rails 3.0.0和以下gems

gem 'rails', '3.0.0'
gem 'capybara'
gem 'database_cleaner'
gem 'cucumber-rails'
gem 'cucumber'
gem 'rspec-rails'
gem 'spork'
gem 'launchy'

senario中有以下内容

When I go to the new customer page
And I fill in "Email" with "[email protected]"

我在我的customer_steps中的 .rb 我

When /^I fill in "([^"]*)" with "([^"]*)"$/ do |arg1, arg2|
  fill_in arg1, :with => arg2
end

认为

- form_for @customer do |f|
  = f.label :email, 'Email'
  = f.text_field :email
  = f.submit

当我运行我的场景时,我收到此错误消息

 Scenario: Register new customer                  # features/manage_customers.feature:7
    When I go to the new customer page             # features/step_definitions/customer_steps.rb:1
    And I fill in "Email" with "[email protected]"  # features/step_definitions/customer_steps.rb:5
      cannot fill in, no text field, text area or password field with id, name, or label 'Email' found (Capybara::ElementNotFound)
      ./features/step_definitions/customer_steps.rb:6:in `/^I fill in "([^"]*)" with "([^"]*)"$/'
      features/manage_customers.feature:9:in `And I fill in "Email" with "[email protected]"'

I'm stuck with the following problem, this is the first time I use capybara, have you an idea how I can solve this issue, thanks

I use rails 3.0.0 and the following gems

gem 'rails', '3.0.0'
gem 'capybara'
gem 'database_cleaner'
gem 'cucumber-rails'
gem 'cucumber'
gem 'rspec-rails'
gem 'spork'
gem 'launchy'

I have the following in my senario

When I go to the new customer page
And I fill in "Email" with "[email protected]"

in my customer_steps.rb I have

When /^I fill in "([^"]*)" with "([^"]*)"$/ do |arg1, arg2|
  fill_in arg1, :with => arg2
end

In my view

- form_for @customer do |f|
  = f.label :email, 'Email'
  = f.text_field :email
  = f.submit

When I run my scenario I get this error message

 Scenario: Register new customer                  # features/manage_customers.feature:7
    When I go to the new customer page             # features/step_definitions/customer_steps.rb:1
    And I fill in "Email" with "[email protected]"  # features/step_definitions/customer_steps.rb:5
      cannot fill in, no text field, text area or password field with id, name, or label 'Email' found (Capybara::ElementNotFound)
      ./features/step_definitions/customer_steps.rb:6:in `/^I fill in "([^"]*)" with "([^"]*)"$/'
      features/manage_customers.feature:9:in `And I fill in "Email" with "[email protected]"'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疯了 2024-09-24 16:38:58

我发现我的错误了!!!

When I go to the new customer page

在这一步之前

When /^I go to (.+)$/ do |page_name|
  path_to page_name 
end

我忘记了访问......

When /^I go to (.+)$/ do |page_name|
  visit path_to(page_name) 
end

I found my mistake!!!

When I go to the new customer page

before the step was

When /^I go to (.+)$/ do |page_name|
  path_to page_name 
end

I forgot the visit...

When /^I go to (.+)$/ do |page_name|
  visit path_to(page_name) 
end
尘曦 2024-09-24 16:38:58

使用该字段的 id 代替,它应该类似于

我用“[电子邮件受保护]填写“customer_email” ”

如果@customer 是对象客户模型

Use this id of the field instead, which should be like

And I fill in "customer_email" with "[email protected]"

if the @customer is a object customer model

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文