Selenium IDE and TinyMCE

25

I created a test case for creating a support ticket.  Our support ticket interface has multiple tinymce editors present for the various ticket description and action update fields.  I had a difficult time find a solution that would make Selenium IDE type text into one of these tinymce editors, but I found one that worked using the dom.  Use command “type” and target should be “dom=document.getElementById(‘id_of_the_tinymce_frame’).contentDocument.body” and the value can be any text you want entered into the tinymce editor.

Note – if you copy and paste the dom code above, you may have to redo the single quotes around the id after you paste it somewhere else.  I did this and the character changed and threw me off for a bit.

This article has 25 comments

  1. Brandon Thomson 01/21/2009, 9:02 am:

    By default “id_of_the_tinymce_frame” appears to be the “name” of the textarea, followed by an underscore, followed by the three letters “ifr”. Posting here since it wasn’t obvious to me. Thanks for the tip though, it works.

    • Schell 10/23/2009, 8:56 pm:

      For me, “id_of_the_tinymce_frame” was the textarea’s “id” followed by “_ifr”. Thanks!

  2. Robert Luong 01/25/2009, 3:23 pm:

    contentDocument doesn’t work in IE.

    Those of you who are testing in IE should use:

    dom=document.getElementById(’id_of_the_tinymce_frame’).contentWindow.document.body

  3. Adam Ashley 02/25/2009, 10:16 pm:

    For those that actually want to use selenium for cross browser testing (you know what it was designed for), use the following sets of commands, works in FF3, IE6 and IE7 with the latest selenium and tinymce

    selectFrame(‘id_of_the_tinymce_frame’)
    // TinyMCE puts an ID of ‘tinymce’ on the body tag of the frame.
    // We want to send our type there for tinymce to pick it up and handle it.
    focus(‘tinymce’)
    type(‘tinymce’, ‘The text you want to input’)
    selectFrame(‘relative=parent’)

  4. torch 10/23/2009, 11:25 pm:

    Thanks a lot, that saved a day. Please keep this site up and running, may will find it useful. Thanks, agian.

  5. Ola 01/28/2010, 11:08 am:

    Hi!

    I just tried this code:
    selectFrame(’id_of_the_tinymce_frame’)
    // TinyMCE puts an ID of ‘tinymce’ on the body tag of the frame.
    // We want to send our type there for tinymce to pick it up and handle it.
    focus(’tinymce’)
    type(’tinymce’, ‘The text you want to input’)
    selectFrame(’relative=parent’)
    It worked fine until you had 2 or more TinyMCEs on the same page.

    This code worked with multiple TinyMCEs:
    “dom=document.getElementById(’id_of_the_tinymce_frame’).contentDocument.body”

    Thanks a lot!

    • Kyle Slater 11/16/2010, 4:11 pm:

      Ola,
      can you give me more details on how to enter text into multiple tinymce’s on a single page?

    • Paul Semeraro 06/20/2011, 11:37 am:

      I don’t know if this is the best solution for the issue, but it worked for me.

      In my case, the test run speed was a little too fast. So, I added a ‘wait’ for an element before the script set focus to the next mce. The solution worked.
      I chose the textarea element id that was being managed by mce. (So, if my iframe ID was ‘test_ifr’ i looked up the corresponding textarea that was named ‘test’.

      Examples:

      waitForElementPresent ‘text_area_name’
      selectFrame ‘tiny_mce_iframe_id’
      focus tinymce
      type tinymce, TEST Text
      selectFrame relative=parent

      waitForElementPresent test
      selectFrame test_ifr
      focus tinymce
      type tinymce, TEST Text
      selectFrame relative=parent

      NOTE: For my code, I placed the test text inside opening and closing ‘p’ tags. If you don’t do that, you will overwrite the ‘p’ tags that are normally present within the mce iframe. My application under test actually looked for those, so I had to keep them in.

    • Paul Semeraro 06/20/2011, 11:40 am:

      Oh, and, uh, I didn’t exactly space out my examples very well in my last post – but I hope everyone gets the idea.

  6. G Kamp 06/24/2010, 8:43 am:

    Thanks guys, dom=document.getElementById(’id_of_the_tinymce_frame’).contentWindow.document.body worked for me, both in FF and IE.

    My version of tinymce (2.1.3) had the following id: ‘mce_editor_0′.

    • nexus 04/10/2012, 12:39 am:

      im using selenium IDE 1.7.2
      With in the site im working on, i have 2 tinymce
      i tried to use dom exampl

      Command: type

      target: dom=document.getElementById(‘mce_edit_requirements_ifr’).contentDocument.body

      value: MyText or MyText

      When I click find for target it works
      no error
      but it does not write the text or value
      can any help…
      thanks

  7. Alejandro Hernandez 11/25/2010, 11:13 pm:

    Thank you, It really works very good!

  8. nilesh 12/15/2010, 10:00 am:

    Any idea on how to select the text inside tinyMCE editor?

    Thanks

  9. JaMo 02/01/2011, 7:58 am:

    Thanks for the silver bullet! Keep ‘em coming.

  10. Paul Semeraro 06/20/2011, 11:18 am:

    Many many thanks to Nick and Adam’s solutions! Adam’s (cross browser) solution worked for me.

    I was specifically looking for a solution that could be implemented within the IDE and this was it!

    I agree with torch – please keep this site up. It took FOREVER to find the best solution for this issue. THANK YOU for keeping it posted.

    Cheers

  11. Rory Slegtenhorst 07/12/2011, 6:35 am:

    Since TinyMCE 3.4.3.2, none of these solutions seem to work for me :(
    And the weird thing is, that the resulting HTML code looks exactly the same…

  12. Boni 01/27/2012, 4:29 pm:

    Hi,

    We recently upgraded to tinyMCE 3.4.7. Before the update, we could access the “id_of_the_tinymce_frame” with the following code:
    “dom=document.getElementById(‘id_of_the_tinymce_frame_ifr’).contentDocument.body”
    After the upgrade, the code no longer works. When it’s executed, it appears to work but nothing is written to the body of the textarea. Has anybody encountered this problem yet? I wonder if tinyMCE 3.4.7 changed the default for “id_of_the_tinymce_frame”. Will appreciate any tip to resolve this problem as it is urgent.
    Thanks.
    Boni

    • Bharat 03/06/2012, 8:04 am:

      Hi Boni, any update on your issue? I am facing a similar problem

      • Boni 03/21/2012, 12:34 pm:

        Bharat,
        Sorry I have not checked back in a while. I am still having the problem and I am currently looking into other ways to achieve the same objective.
        Boni

  13. Peter 03/07/2012, 9:38 am:

    Hi I had the same issue. I fixed it like this:

    runScript
    tinyMCE.get(“text”).setContent(‘Selenium test page text’)

    where “text” is id of tinymce textarea

    • Boni 03/21/2012, 12:36 pm:

      This seems that it will work for pure text. How about HTML content, which is what I am trying to insert?

Trackbacks/Pings

Leave a Reply

Your email address will not be published. Required fields are marked *

*




You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">