Capybara and content

How do you use Capybara to test elements with contenteditable="true" ?

Using this specification ...

 scenario "Using valid input" do fill_in "name", with: "Zinn" click_button "Update" expect(page).to have_content("Update successful!") end 

... and this eco file ...

 <td id="name" contenteditable="true"><%= @name %></td> <td><button id="update" class="btn btn-sm btn-default">Update</button></td> 

I get this unsuccessful specification ...

 Capybara::ElementNotFound: Unable to find field "name" 
+6
source share
1 answer

This is how I decided to solve the problem.

 feature "Editing", js: true do scenario "with valid input" do el = find(:xpath, "//div[@contenteditable='true' and @name='name']") el.set("Zinn") el.native.send_keys(:return) expect(page).to have_content("Update successful!") expect(page).to have_content("Zinn") end end 

According to this thread , it looks like you should use the fill_in for content div declarations, but I couldn't get to work.

+8
source

All Articles