6

I'm currently trying to automate test cases where I need to enter values for a required Text Area field.

The text area uses TinyMCE 3.4.9

I found a blog online that suggested selectFrame (iFrame containing tinymce) focus (tinymce) type (tinymce, text)

that didn't help since Selenium RC can't locate the iframe. However, I tried this with the Firefox plugin and at the very least I can select the iframe and focus the editor, but I can't enter any text. With RC, nothing I do seems to work

I also tried entering text using the html editor. So selenium can emulate clicking the button to open the html editor, then RC would either fail to find the text area or I'll get an error such that the element is no longer attached to the DOM (something along that line)

Sorry if this sounds confusing.

Josh
  • 61
  • 1
  • 2

13 Answers13

11

This worked for me:

command: runScript target: tinyMCE.activeEditor.setContent('Replace with your text')

Got it from http://www.tinymce.com/forum/viewtopic.php?id=27960

Dejan
  • 9,150
  • 8
  • 69
  • 117
3

If you have multiple tinyMCE forms on one page, I recommend
Command: runScript
Target: tinyMCE.get('textarea_id').setContent('Your Text')

ljavor
  • 116
  • 7
2

Firstly you switch to frame

// driver is type of IWebDriver
driver.switchTo().frame(frameName or frameIndex);

Then you get element by id and fill it with your text

 var el = driver.findElement(By.id("tinymce"));
 el.sendKeys("YOUR TEXT");
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
312k1t
  • 269
  • 1
  • 4
  • 10
1

WebElement bodyIframe = driver.findElement(By.tagName("iframe")); driver.switchTo().frame(bodyIframe); WebElement mce = driver.findElement(By.id("tinymce")); mce.sendKeys("This is for testing!!!!");

This worked perfectly for me

Vicky
  • 2,999
  • 2
  • 21
  • 36
0

The only way I am able to get Selenium testing to work with TinyMCE is to not use TinyMCE for the test.

Use some server-side wizardry to selectively disable the TinyMCE plugin under test conditions.

This will not help you with testing the use of TinyMCE itself, but you will at least be able to fill in the form to completion and move your tests forward... :)

datashaman
  • 8,301
  • 3
  • 22
  • 29
0

For TinyMCE 3.4.x and Selenium IDE in Firefox, this is working for me. Substitute the id of your TinyMCE instance for NAME below:

<tr>
    <td>type</td>
    <td>dom=document.getElementById('NAME_ifr').contentDocument.body</td>
    <td>Editor content</td>
</tr>

This is based on https://gist.github.com/809728

pents90
  • 1,782
  • 17
  • 17
0

We use the process described at techiebyday.blogspot.com, and it works great in current versions of Selenium RC (at least up to 2.20) and TinyMCE (post-3.4). In C#, it looks like this:

string editorFrameId = editorId + "_ifr";
selenium.Focus(String.Format("dom=document.getElementById('{0}').contentWindow.document.body", editorFrameId));
selenium.GetEval(String.Format("selenium.browserbot.getCurrentWindow().document.getElementById('{0}').contentWindow.document.body.innerHTML = '{1}';", editorFrameId, fillString));
Ross Patterson
  • 9,527
  • 33
  • 48
0

I've been trying to use this solution:

<tr>
  <td>type</td>
  <td>dom=document.getElementById('NAME_ifr').contentDocument.body</td>
  <td>Editor content</td>
</tr>

Replaced 'name_ifr'. First to frame name and inserted before entering into the tinymce frame and then replaced name with 'tinymce' and inserted after entering the frame where accoring to all the rules typing must happen. But all I get is errors. Somehow, I never make DOM or js commands work in my script. Is there something I am missing?

Ieva
  • 31
  • 2
  • 6
0

If you have one TinyMCE element in page:

var obj = ((IJavaScriptExecutor)webDriver).ExecuteScript("tinyMCE.activeEditor.setContent('" + text + "');");
Babak
  • 3,716
  • 6
  • 39
  • 56
0

I was having problems entering text in a tinyMCE editor too:

  • FireFox 20.01
  • tinyMCE 3.4.9
  • Selenium IDE 1.10.0

I have multiple tinyMCE editors in my form.

Solution (using Selenium IDE, which can be ported to Selenium RC easily):

  • Using firebug, find out the id of the tinymce iframe that replaces the textarea, e.g. form_editor1_ifr
  • Strip the "_ifr" from this id to get the id of the original textarea
  • Use this id in the target for the runScript command in Selenium IDE: tinyMCE.get('form_editor1_ifr').setContent('the content');
Peter
  • 3
  • 2
0

In Selenium webdriver PHPUnit_Extensions_Selenium2TestCase, this works when you use:

$this-> execute(array('script' => "tinymce.get('cms_cpg_content').setContent('Lorem ipsum dolor sit amet,...')", 'args' => array()));

When you want to add text.

jam
  • 3,640
  • 5
  • 34
  • 50
0

I was able to solve this problem using Selenium RC, have done following steps(attached screenshot for your referral)

  1. on tinyMCE editor, click on Advanced option icon
  2. Click on "<>" source code icon
  3. Source code popup appears, enter text and click Ok
  4. text appears in TinyMCE editor enter image description here

Just for your reference I have given steps with CSS locator

  • click on advaced option button: css= tr[id*='tinymce'] td * div[aria-label='Advanced Options'] button

  • click on source code: css= tr[id*='tinymce'] td * div[aria-label='Source code'] button

  • click on popup textarea css= div[class*='mce-floatpanel'][aria-label='Source code'] * textarea

  • click on ok button on popup css= div[class*='mce-floatpanel'][aria-label='Source code'] * div>button:contains('Ok')

  • verify text present in tinymce css=body p:contains(this is testing)

Hope this will solve your problem :)

user3181500
  • 401
  • 1
  • 5
  • 12
-1

http://odino.org/typing-into-tinymce-with-selenium/ ...looks like TinyMCE and selenium IDE hook ups don't work on 3.4.5, so my presumption is that this issue has been carried over into 3.4.9.

Greg
  • 5,422
  • 1
  • 27
  • 32