Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

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

1 Answer

0 votes
by (62.9k points)

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!'

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...