Reputation: 10350
Here is the html source code for 2 Save
buttons in Rails 4
spec. The program should click the first Save
:
<div class="btn-toolbar">
<a class="btn btn-primary" href="/view_handler?index=0">
<span class="translation_missing" title="translation missing: en.Back">Back</span>
</a>
<input class="btn btn-default btn btn-primary" name="commit" value="Save" type="submit">
<input class="btn btn-default btn btn-primary" name="commit" value="Save & New" and_new="true" type="submit">
</div>`
Here is the code I tried:
first('input.btn.btn-default').click_button 'Save'
The error returned is:
Capybara::ElementNotFound: Unable to find button "Save"
What's the right way to click button Save
in spec?
Upvotes: 0
Views: 2243
Reputation: 411
The buttons have different text value one is 'Save' and the other 'Save & New'
within '.btn-toolbar' do
click_button 'Save'
end
Should work for your case.
Upvotes: 2