Capybara::ElementNotFound 远程 true 问题
Capybara::ElementNotFound issue with remote true
我有一个要使用 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"%>
<% end %>
<span style="font-weight: bold;">Converted Amount:</span>
<div id="converted_amount"></div>
提交表单时,转换后的值显示在 div 中,id 为
#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: Unable to find xpath "/html" and yet when I comment out click_button, it works.
我做错了什么?
这是我的解决方案:
我将以下 gem 添加到我的 Gemfile
gem 'capybara-webkit'
gem 'selenium-webdriver'
然后将 :js => true
添加到我的规范文件中。变成了:
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
我有一个要使用 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"%>
<% end %>
<span style="font-weight: bold;">Converted Amount:</span>
<div id="converted_amount"></div>
提交表单时,转换后的值显示在 div 中,id 为
#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: Unable to find xpath "/html" and yet when I comment out click_button, it works.
我做错了什么?
这是我的解决方案:
我将以下 gem 添加到我的 Gemfile
gem 'capybara-webkit'
gem 'selenium-webdriver'
然后将 :js => true
添加到我的规范文件中。变成了:
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