Posts RSS Comments RSS 4 Posts and 0 Comments till now

Selenium and TinyMCE

For many projects, my shop uses TinyMCE for a quick and feature rich WYSIWYG editor. While its simple to implement, it can be awful to automate. Using Selenium type, click, click_at, etc will not work (I suspect because the editor is technically external from the page were testing, see below).

Initially my problem was that I did not allow enough for the page to load before using JS to enter info in to the box. To rectify this, I used time.sleep(5).

Next the issue arose that enterring characters via JS did not register with the character counting mechanism. Since i’m on a time based budget, I can’t spend too much time on this but I figure using os (python) or keypress/keydown in JS will do the trick.

This is the code to use when encountering a TinyMCE box.

First use mceFocus to get the id of the text field you wish to alter, in this case id=”body”:

tinyMCE.execCommand(‘mceFocus’,false,’body’);
(In my experience the text area will appear as light gray [hidden] in firebug.)

Next, set the text by using mceInsertContent:

tinyMCE.execCommand(“mceInsertContent”, false, “body text”);
(This will enter your string, but be cautious, enforced character limits will
not allow this will complain).

In Selenium IDE:

tinyMCE.execCommand(‘mceFocus’,false,’body’);tinyMCE.execCommand(“mceInsertContent”, false, “body text”);

So ‘body text’ will be inserted into the textarea with id ‘body’.

In Python:

sel.run_script(“tinyMCE.execCommand(‘mceFocus’,false,’body’);tinyMCE.execCommand(‘mceInsertContent’, false, ‘body text’);”)

Trackback this post | Feed on Comments to this post

Leave a Reply