Capybara选择方法无法找到单选按钮

 男孩花朵 发布于 2023-01-31 17:46

我有一个由简单形式生成的表单:

TL TR
TL TR

我有一个这样的简单规范:

# encoding: UTF-8
require 'spec_helper'

feature 'Register' do

  background do
    visit new_user_registration_path
  end

  scenario 'fill register form and register' do
    # TL TR
    choose('user_register_temp_attributes_domain_package_id_1')
    # TL TR
  end

end

我的spec_helper.rb是

ENV['RAILS_ENV'] ||= 'test'
require File

.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'

Capybara.javascript_driver = :webkit
Capybara.default_selector = :css

Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }

ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)

RSpec.configure do |config|
  # ## Mock Framework
  #
  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
  #
  # config.mock_with :mocha
  # config.mock_with :flexmock
  # config.mock_with :rr

  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, remove the following line or assign false
  # instead of true.
  config.use_transactional_fixtures = true

  # If true, the base class of anonymous controllers will be inferred
  # automatically. This will be the default behavior in future versions of
  # rspec-rails.
  config.infer_base_class_for_anonymous_controllers = false

  # Run specs in random order to surface order dependencies. If you find an
  # order dependency and want to debug it, you can fix the order by providing
  # the seed, which is printed after each run.
  #     --seed 1234
  config.order = 'random'

  # Capybara DSL
  config.include Capybara::DSL

  # Factory girl
  config.include FactoryGirl::Syntax::Methods

end

choose方法的Capybara API 说:

"找到一个单选按钮并将其标记为已选中.单选按钮可以通过名称,ID或标签文本找到."

但是当我运行规范时choose('user_register_temp_attributes_domain_package_id_1'),我得到了 Capybara::ElementNotFound: Unable to find radio button "user_register_temp_attributes_domain_package_id_1"

我尝试过以下代码,但收到Capybara::ElementNotFound: Unable to find css "user_register_temp_attributes_domain_package_id_1"错误:

find('#user_register_temp_attributes_domain_package_id_1[value=1]').set(true)

这似乎是没有问题fill_in,checkclick_button方法.

问候.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有