0
votes

I am writing feature tests for my Rails 5 application. One feature is the ability to click a link with method POST.

visit "/admin/client_servers/#{client_server.id}"
click_on('Request Review From Application Owner')

I receive the error "Capybara::ElementNotFound: Unable to find link or button 'Request Review From Application Owner'"

Just experimenting, I check to see if the test can find any element I know is on the screen. I have one container div with a class of 'description' and the test is unable to find the element.

The previous test passes

  visit "/admin/client_servers/#{client_server.id}"
  expect(page).to have_text("Request Review From Application Owner")

So I know the text I want to click on appears on the page. My html is setup:

<div class="mark-ready-btn server-button" id="overall-tab" data-param="overall">
    <%=link_to admin_client_servers_update_review_status_path(status: 1, id: @server.id), class: "request-review-btn", method: 'POST' do%>
      <div class="server-mark-ready" id="overall-tab" data-param="overall">
        Request Review From Application Owner
      </div>
    <%end%>
</div>

I've checked but the test is unable to find the css tags '.mark-ready-btn server-button', '.request-review-btn', or '.server-mark-ready'. I've searched this problem online and looked into Capybara and Rspec documentation. Is there something I'm missing or a improper syntax I've written in the test? I'd appreciate any help on this issue.

3
Have you tried click_link instead of click_on? See this answer for detailed explaination stackoverflow.com/a/17564749/1202324 . Since you have a div inside of your a capybara could be confused and does not see it as a link or button.Denny Mueller
What version of Capybara are you using? What driver are you using? Is your document being served with the HTML5 doctype or is it being served as HTML4 ? Also, please look at page.html and find the relevant part of the actual HTML that is being processed and add that to your question.Thomas Walpole
try to find the id=overall-tab you have your div find("#overall-tab").clickjohan

3 Answers

1
votes

You can try -

within ".mark-ready-btn.server-button" do
  click_on ".server-mark-ready"
end

Or you can use "find"

find('.server-mark-ready').click
0
votes

If Capybara can't find link or button, generally means that there is no link or button. You will have to use 'click' method.

From your html example, this should work

1.first('.server-mark-ready).click
2.page.all('.server-mark-ready)[#].click (in case there is more than one div that has that class)
0
votes

find("#overall-tab").click should do the work

Or if you really want to click on specific text try:

find('div', text: 'Request Review From Application Owner').click