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

佐手、 提交于 2019-12-20 18:45:12

问题


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.


回答1:


I know that this is an old question but I just found it while trying to solve this issue as well.

Although the original question said that he has 7 tinymce's on the same page I think that my solution might work for him too but I do know it will work if there is one tinymce as was my case.

In my request spec I used this:

page.execute_script('$(tinymce.editors[0].setContent("my content here"))')

The page.execute_script with tell it to run the jQuery function. It then finds the first tincymce editor and sets the content.

Worked like a charm for me. I think if there are more than one tinymce it can be called by its position.




回答2:


Switching to chrome as described here solved my problem.

Obviously the problem is related with a bug in firefox driver.

Still i think it is a valid question for firefox.




回答3:


Try to switch to an iframe that contains tinymce textarea input, and than send_keys:

# +session+ is an instance of Capybara::Session class
browser = session.driver.browser
browser.switch_to.frame(iframe_id)
editor.native.send_keys(text)
browser.switch_to.default_content



回答4:


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



来源:https://stackoverflow.com/questions/11581474/how-to-fill-tinymce-rails-editor-with-capybara-and-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!