I have a textarea with the id of “request_details”, made into a CKEditor instance by jQuery: $(‘#request_details’).ckeditor();
(Check this page if you need some help getting CKEditor to work with jQuery, it’s dead simple)
Feature looks like this: And I fill in "Here are some details" in the CKEditor instance "request_details"
Step looks like this:
When /^I fill in "([^"]*)" in the CKEditor instance "([^"]*)"$/ do |value, input_id|
browser = page.driver.browser
browser.execute_script("CKEDITOR.instances['#{input_id}'].setData('#{value}');")
end
July 5, 2011 at 2:34 am
I’ll try to put this to good use immdieaetly.
LikeLike
February 22, 2012 at 8:29 pm
worked a treat for me once I set Capybara to use :selenium driver rather than :webkit, thanks!
LikeLike
February 25, 2012 at 12:48 am
Worked for me. Thanks!
LikeLike
May 8, 2012 at 2:15 pm
Most helpful, thanks.
To be complete, it’s probably best to replace the ‘#{value}’ with #{value.to_json}, as this will escape quotes and thus avoid potential javascript errors.
@Michael: Works perfectly for me with capybara-webkit
LikeLike
June 8, 2012 at 10:15 pm
Strangely enough, it didn’t work anymore with webkit, even though the script executed correctly and getData() returned the correct string. I came up with an extended solution, see http://stackoverflow.com/questions/10957869/how-to-fill-ckeditor-from-capybara-with-webkit-or-selenium-driver
LikeLike
September 11, 2012 at 5:37 am
browser.execute_script(“CKEDITOR.instances.SELECTOR.setData(‘test’)”)
LikeLike
February 26, 2014 at 5:21 am
Great tip, thanks.
Note to those using Poltergeist:
browser.execute_script will not work, instead use:
browser.execute
LikeLike