Capybara :: ElementNotFound问题与远程true

时间:2017-09-04 15:28:45

标签: ruby-on-rails rspec capybara

我有一个表单,我使用remote => true

提交
<%= form_tag fetch_data_path, :remote => true do %> 
    Date: <%= text_field_tag :date %>
    Amount:<%= text_field_tag :amount %>
    From:<%= text_field_tag :from %>
    To:<%= text_field_tag :to %>

 <%= submit_tag "Convert"%> &nbsp;

<% end %>


<span style="font-weight: bold;">Converted Amount:</span> 
<div id="converted_amount"></div>

在提交表单时,转换后的值将显示在ID为

的div中
  

#converted_amount

这是我的rspec:

RSpec.feature "User performs exchange", :type => :feature do
  scenario "with valid input" do
    visit exchanges_path
    fill_in 'date', :with => "2017-08-24"
    fill_in 'amount', :with => "100"
    fill_in 'from', :with => "pound"
    fill_in 'to', :with => "dollar"
    click_button('Convert')

    expect(page).to have_text("Converted Amount:")
  end
end

问题在于,当我运行它时,我得到了

  

Capybara :: ElementNotFound:无法找到xpath&#34; / html&#34;然而当我发表评论click_button时,它的确有效。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

这是我的解决方案:

我将以下宝石添加到我的Gemfile

  gem 'capybara-webkit'
  gem 'selenium-webdriver'

然后将:js => true添加到我的spec文件中。它变成了:

RSpec.feature "User performs exchange", :type => :feature do
  scenario "with valid input", :js => true do
    visit exchanges_path
    fill_in 'date', :with => "2017-08-24"
    fill_in 'amount', :with => "100"
    fill_in 'from', :with => "pound"
    fill_in 'to', :with => "dollar"
    click_button('Convert')

    expect(page).to have_text("Converted Amount:")
  end
end