您如何使用水豚用contenteditable="true"
测试元素?
使用此规格...
scenario "Using valid input" do
fill_in "name", with: "Zinn"
click_button "Update"
expect(page).to have_content("Update successful!")
end
...和这个环保文件...
<td id="name" contenteditable="true"><%= @name %></td>
<td><button id="update" class="btn btn-sm btn-default">Update</button></td>
我得到这个失败的规格...
Capybara::ElementNotFound:
Unable to find field "name"
这就是我最终解决问题的方式。
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
根据this thread,看来您应该能够在内容可编辑的div上使用fill_in
帮助程序,但我无法使用它。
2020年我可以做到]
find('.selector').send_keys 'this text gets filled in'