Reputation:
I am using capybara, rspec, and poltergeist in a Rails 4 application and am trying to click on the following link button via capybara.
<div class="form-group">
<input id="invoice_invoice_items_attributes_0__destroy" name="invoice[invoice_items_attributes][0][_destroy]" type="hidden" value="false">
<a class="btn btn-warning remove_fields existing" href="#">Remove Invoice Item</a>
</div>
If I have the following in rspec/capybara, it finds the hidden element:
find(:xpath, '//input[@id="invoice_invoice_items_attributes_0__destroy"]', visible: false)
If I try this, it doesn't find the link element:
find(:xpath, '//input[@id="invoice_invoice_items_attributes_0__destroy"]/a', visible: false)
The end goal is to do this:
find(:xpath, '//input[@id="invoice_invoice_items_attributes_0__destroy"]/a', visible: false)
How do I get there?
Upvotes: 0
Views: 3620
Reputation: 13581
Your a
tag isn't inside of the input
field, so unless form-group
div is hidden, you should be able to just do:
click_link 'Remove Invoice Item'
If form-group
is hidden, then try:
find(".remove_fields", visible: false).click
Upvotes: 2