Permalink
Browse files

allow filling in contenteditable elements

  • Loading branch information...
1 parent 0320ab6 commit 4feba83ca2873865f74a812fe3af52619f243b99 @JonRowe committed Dec 14, 2012
Showing with 25 additions and 1 deletion.
  1. +7 −0 lib/capybara/selenium/node.rb
  2. +12 −0 lib/capybara/spec/session/fill_in_spec.rb
  3. +5 −0 lib/capybara/spec/views/with_js.erb
  4. +1 −1 xpath
@@ -34,6 +34,13 @@ def set(value)
elsif tag_name == 'textarea' or tag_name == 'input'
driver.browser.execute_script "arguments[0].value = ''", native
native.send_keys(value.to_s)
+ elsif self[:contenteditable]
+ if native.text == ''
+ #workaround for selenium raising an ElementNotVisible on empty elements
+ driver.browser.execute_script "arguments[0].innerHTML = ' '", native
+ end
+ native.clear
+ native.send_keys(value.to_s)
end
end
@@ -103,6 +103,18 @@
extract_results(@session)['first_name'].should == 'Harry'
end
+ it 'should allow me to change the contents of a contenteditable element', :requires => [:js], :contenteditable => true do
+ @session.visit('/with_js')
+ @session.fill_in('existing_content_editable', :with => 'WYSIWYG')
+ @session.find(:css,'#existing_content_editable').text.should == 'WYSIWYG'
+ end
+
+ it 'should allow me to set the contents of a contenteditable element', :requires => [:js], :contenteditable => true do
+ @session.visit('/with_js')
+ @session.fill_in('blank_content_editable', :with => 'WYSIWYG')
+ @session.find(:css,'#blank_content_editable').text.should == 'WYSIWYG'
+ end
+
context 'on a pre-populated textfield with a reformatting onchange', :requires => [:js] do
it 'should only trigger onchange once' do
@session.visit('/with_js')
@@ -36,6 +36,11 @@
</p>
<p>
+ <div contenteditable='true' id='existing_content_editable'>Editable content</div>
+ <div contenteditable='true' id='blank_content_editable'></div>
+ </p>
+
+ <p>
<input type="checkbox" id="checkbox_with_event"/>
</p>
2 xpath
Submodule xpath updated from df56bb to 8b0514

0 comments on commit 4feba83

Please sign in to comment.