1

Topic: TinyMCE getContent

Dear Sirs,

In our web application we are using the tinymce editor. I'm trying to created an automation framework, and so far i haven't got any problems with writing into the tinymce editor. What I would like to do now is retrieve the text in textarea. I have tried various methods which i found online however none of them have been successfull, and i'm always getting a NULL value. The text is being entered successfully through selenium webdriver. I have tried some of the examples below, however no success:

tinyMCE.activeEditor.getContent();

tinyMCE.activeEditor.get('tinymce').getContent();

It would be really appreciated if you can provide any feedback.

Thanks.

Last edited by sengaia (2012-06-11 16:02:35)

2

Re: TinyMCE getContent

Could be a sync problem. If you modify the value of a textarea with code you need to call the tinymce.activeEditor.load(); to move the contents from the textarea into the editor iframe.

Best regards,
Spocke - Main developer of TinyMCE

3

Re: TinyMCE getContent

sengaia wrote:

Dear Sirs,

In our web application we are using the tinymce editor. I'm trying to created an automation framework, and so far i haven't got any problems with writing into the tinymce editor. What I would like to do now is retrieve the text in textarea. I have tried various methods which i found online however none of them have been successfull, and i'm always getting a NULL value. The text is being entered successfully through selenium webdriver. I have tried some of the examples below, however no success:

var ed = tinymce.activeEditor; /* editor instance */

/* use these if necessary - and swap the order if necessary */
ed.load(); /* copy textarea content into editor */
ed.save(); /* copy editor content into textarea */

var textarea = ed.getElement().value; /* get the value of the entire textarea */
var selected_in_editor = ed.selection.getContent(); /* get the editor selected text only */
var all_in_editor = ed.getContent(); /* get the entire editor content */

var text = '<p>Hello there!</p>'; /* create a simple HTML line */

ed.execCommand('mceReplaceContent', false, text); /* replace selected text with "content" (note 1) */
ed.selection.setContent(text); /* replace selected text with "content" (note 2) */

ed.execCommand('mceInsertContent', false, text); /* insert text at the cursor position */
ed.setContent(text); /* set the entire editor content to "text" */

ed.getElement().value = text; /* set the entire textarea to "text" */
ed.load(); /* synchronize modified textarea into editor */

Note 1: Use this code to replace a selection.
Note 2: This code sometimes screws up in MSIE if there is no selection set.

Hopefully one or more of these will be of help to you.....

Last edited by Krupski (2012-06-11 16:58:26)

"Anything that is complex is not useful and anything that is useful is simple. This has been my whole life's motto." -- Mikhail T. Kalashnikov

4

Re: TinyMCE getContent

Thanks for your help guys, I have actually given a try to the solutions you provided here however still no success. Basically for now I decided that I will assert that the text is there by checking the page source. However it would be nice that make it work the correct way by checking the tinymce textarea. I will post again if I will be able to make it work!

Thanks.