How to fill tinymce-rails editor with capybara and selenium?

Viewed 2701

I have trouble with using capybara to test tinymce form. I'm using tinymce-rails and have 7 editors in my form. Also I'm using asciimath plugin with tinymce.

Everything works fine, but I'm unable to write tests to fill in tinymce editor.

Here is how my step definition code looks like, very similar to what is described here:

within_frame("content_ifr") do
  editor = page.find_by_id('tinymce')
  editor.native.send_keys 'test'
end

The problem is when I run the following:

editor.native.clear            # works, clear the editor area, I'm testing this with pry
editor.native.send_keys :tab   # works, moves focus to next input
editor.native.send_keys 'test' # returns "", nothing happens, nothing in editor

So clear and send_keys :tab work as expected. But I can't send any string. send_keys function is always returning empty string, and nothing happens when I do test using pry.

What is going wrong here? and how can I debug / investigate the problem?

Thanks.

5 Answers

I had the same issue. After a day fighting, my tests finally passed.

The code that I am using is:

within_frame("producto_condiciones_ifr") do
  editor = page.find_by_id('tinymce')
  editor.native.send_keys 'filling text'
end

The first line is a method of capybara. The parameter passed is the ID of the iframe.

Line #2 is a must.

In line #3 goes the text that you wish to place inside TinyMCE

just came across this problem with RoR and rspec

I managed to solve by doing this:

within_frame { page.find_by_id("tinymce").set("new content here") }

the set method will replace any existing content by the new one

if you want to keep the current content and add things to it, use the send_keys method

Related