Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add support for contenteditable elements. #533

Closed
wants to merge 1 commit into from

4 participants

@david

This is based on #182, but I also added support for rack-test. Please let me know if any changes are needed.

@jnicklas
Owner

There have been discussions surrounding this, somewhere on another issue or on the mailing list before. We came to the conclusion that it's not a good idea to add this.

@jnicklas jnicklas closed this
@williscool

Can you provide a link to this discussion?

The pages with these closed pull requests and issues are at the topic of the front page in the google search for

"capybara contenteditable"

@JonRowe

+1 for a link to the discussion, cant find it by google myself, it seems like we should be able to edit the content of these elements...

@jnicklas
Owner

I can't remember where the discussion took place, and google and github didn't help me either. But regarding this pull request, the question is: what would you do with this functionality. As far as I can see contenteditable really has no purpose in a driver which doesn't support JavaScript. contenteditable elements aren't treated as form elements, and thus aren't submitted along with form data.

I tried really hard to come up with a case where changing an element due to it having contenteditable would cause any kind of effect at all in the absence of JavaScript, and the only thing I could come up with is something like this:

<button type="submit" contenteditable="true" name="button">Change me</button>

A contenteditable button. Curisouly, I tried this in Chrome and yes, it does work, but it's a pretty ludicrous edge case isn't it?

Why then support something which doesn't make any sense. Note that Selenium already supports it, it just isn't tested.

@JonRowe

I agree it makes no sense in drivers that don't support JS (other than uniformity maybe) but it does make sense for the JS drivers. Looking at the head it doesn't look like the selenium driver would support it as set doesn't do anything for element's it doesn't know how to manipulate, and content-editable is never mentioned, so you'd have to drop down to native and send_keys yourself... which makes me sad...

I'd be open to writing some tests for and making it work on selenium if the behaviour is agreeable but as the previous two PR's with this functionality have been rejected and I'm using a different driver anyway (poltergeist)...

@jnicklas
Owner

@JonRowe I'm working on a major refactor of the test suite, which will affect how these tests would be written. I should be able to finish that up in the next couple of days. I'd suggest holding off until then, if you're interested in making this work in Selenium.

@jonleighton jonleighton referenced this pull request in teampoltergeist/poltergeist
Closed

Allow set or editing of content-editable #113

@JonRowe

See pull request #911

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 27, 2011
  1. @david

    Support contenteditable.

    david authored
This page is out of date. Refresh to see the latest.
View
2  lib/capybara/rack_test/node.rb
@@ -32,6 +32,8 @@ def set(value)
native['value'] = value.to_s
elsif tag_name == "textarea"
native.content = value.to_s
+ elsif native['contenteditable'] == 'true'
+ native.content = value
end
end
View
2  lib/capybara/selenium/node.rb
@@ -22,7 +22,7 @@ def set(value)
click
elsif tag_name == 'input' and type == 'checkbox'
click if value ^ native.attribute('checked').to_s.eql?("true")
- elsif tag_name == 'textarea' or tag_name == 'input'
+ elsif tag_name == 'textarea' or tag_name == 'input' or native.attribute('contenteditable') == 'true'
resynchronize do
native.clear
native.send_keys(value.to_s)
View
11 lib/capybara/spec/driver.rb
@@ -295,3 +295,14 @@
end.should raise_error(Capybara::InfiniteRedirectError)
end
end
+
+shared_examples_for "driver with contenteditable support" do
+ before do
+ @driver.visit('/content_editable')
+ end
+
+ it "should allow assignment to nodes with contenteditable attribute true" do
+ @driver.find(%Q{//*[@contenteditable='true']}).first.set('Bufoon')
+ @driver.find(%Q{//*[@class='edit-me']}).first.text.should == 'Bufoon'
+ end
+end
View
3  lib/capybara/spec/views/content_editable.erb
@@ -0,0 +1,3 @@
+<p>I'm not editable</p>
+<p contenteditable="true" class="edit-me" style="min-height: 1px"></p>
+
View
1  spec/driver/rack_test_driver_spec.rb
@@ -30,6 +30,7 @@ def capture(*streams)
it_should_behave_like "driver with status code support"
it_should_behave_like "driver with cookies support"
it_should_behave_like "driver with infinite redirect detection"
+ it_should_behave_like "driver with contenteditable support"
describe '#reset!' do
it { @driver.visit('/foo'); lambda { @driver.reset! }.should change(@driver, :current_url).to('') }
View
1  spec/driver/selenium_driver_spec.rb
@@ -13,6 +13,7 @@
it_should_behave_like "driver with support for window switching"
it_should_behave_like "driver without status code support"
it_should_behave_like "driver with cookies support"
+ it_should_behave_like "driver with contenteditable support"
unless Config::CONFIG['host_os'] =~ /mswin|mingw/
it "should not interfere with forking child processes" do
Something went wrong with that request. Please try again.