How to fill ckedito...
 
Notifications
Clear all

How to fill ckeditor from capybara with webkit or selenium driver  

  RSS

Abhijith
(@abhijith)
Noble Member
Joined: 4 months ago
Posts: 1161
31/03/2021 12:05 pm  

How can I fill a CKEditor area within Capybara, assuming I'm using a javascript capable driver like capybara-webkit or selenium?

 


Quote
Ganesh A
(@ganesh)
Noble Member
Joined: 4 months ago
Posts: 1170
31/03/2021 12:05 pm  

Here's a solution in which by using javascript both to set the data on the hidden textarea and on the CKEditor object.

def fill_in_ckeditor(locator, opts)

  content = opts.fetch(:with).to_json # convert to a safe javascript string

  page.execute_script <<-SCRIPT

    CKEDITOR.instances['#{locator}'].setData(#{content});

    $('textarea##{locator}').text(#{content});

  SCRIPT

end

 

# Example:

fill_in_ckeditor 'email_body', :with => 'some message!'

This post was modified 2 weeks ago by Ganesh A

ReplyQuote
Share: