Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Allow contenteditable elements as fillable fields #48

wants to merge 1 commit into from

2 participants


Companion commit, branch, pr, etc to jnicklas/capybara#911

@JonRowe JonRowe referenced this pull request in jnicklas/capybara

Support filling in `contenteditable` elements #911


I don't like this. While contenteditable elements are editable, they are distinctly not fields. In the context of Capybara it kind of makes sense that we would allow contenteditable fields for fill_in, but even there, those elements behave quite differently from actual fields. They can't have labels for instance. This doesn't provide any functionality that Capybara currently cannot offer, after all, you can just do find("#foo").set("bar") instead of fill_in, and it just confuses the semantics of fill_in needlessly. This has been suggested previously, (even with a pull request, iirc) and I turned it down then, my position hasn't changed since.


To me, fill_in 'x', with: 'text' doesn't semantically say "fill in field x with text". It say's, "user is providing text for x", and contenteditable elements are perfectly acceptable targets, especially as this is a pretty usable part of the HTML5 spec.

I will defer to your opinion on the finding field xpath, your library, your preference and all but please don't discard the other pull request, jnicklas/capybara#911, it's still valid, as find('#contenteditable').set('text') won't work as it stands.


We're still working out the details of jnicklas/capybara#911, and I hope we'll eventually merge it, but I'm closing this pull request.

@jnicklas jnicklas closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 14, 2012
  1. @JonRowe
This page is out of date. Refresh to see the latest.
2  lib/xpath/html.rb
@@ -71,7 +71,7 @@ def field(locator)
def fillable_field(locator)
locator = locator.to_s
- xpath = descendant(:input, :textarea)[~attr(:type).one_of('submit', 'image', 'radio', 'checkbox', 'hidden', 'file')]
+ xpath = descendant(:input, :textarea,:"*[@contenteditable]")[~attr(:type).one_of('submit', 'image', 'radio', 'checkbox', 'hidden', 'file')]
xpath = locate_field(xpath, locator)
1  spec/fixtures/form.html
@@ -18,6 +18,7 @@
<a href="#has-children" data="link-children">
An <em>emphatic</em> link with some children
+ <div id='content' contenteditable='true' data='an-editable-content-div'></div>
1  spec/html_spec.rb
@@ -176,6 +176,7 @@ def all(*args)
context "by parent label" do
it("finds inputs with text type") { get('Label text').should == 'id-text' }
it("finds inputs where label has problem chars") { get("Label text's got an apostrophe").should == 'id-problem-text' }
+ it("finds contenteditable elements") { get('content').should == 'an-editable-content-div' }
Something went wrong with that request. Please try again.