Reputation: 695
I have searched this for some good time in SO, and on Google. I am a newbie(only 7 months in development), but I'd like an explanation as to why capybara's click_button
does not respond to buttons that are not in forms
take and example of this
<div id="btn-div">
<%= button_tag('Attach new file', id: "attach-file-btn", class: "btn btn-info") %>
</div>
in this case when you are writing tests you get an error of the type
undefined method `node_name' for nil:NilClass
however when you put this in a form
like this it works
<form id="btn-form">
<%= button_tag('Attach new file', id: "attach-file-btn", class: "btn btn-info") %>
</form>
if you may, please provide an explanation as to why this happens.
and take the following into consideration
xpath
or find
it is available, however click_button
does not work for itupdate
code for click button is similar to this:
describe "Getting to the deployable tools page" do
before do
@tool = FactoryGirl.create(:tool)
@tool.set_status(1)
end
before { visit assigned_tools_path }
before { click_button('attach-file-btn') }
it { should have_content('select tools to add') }
it { should have_css('#non-successful-tool-adding') }
end
Upvotes: 0
Views: 627
Reputation: 916
Try using a capybara finder, and then invoke click on it, like so:
page.find('#attach-file-btn').click
Upvotes: 2
Reputation: 888
If you just want to click the file show at broswer with text Attach new file
, use:
click_button 'Attach new file'
Upvotes: 0