RTE and Selenium.

An interesting issue quick I came across while trying to automate action on the RTE was the inability to directly address the xpath of the text area to write into it.

Here is the source code snippet for the RTE:

<div class="<span class=">yui"</div>
 <iframe = id-"editor_editor" class......>
   <head> ............
   <body onload="document.body._rteLoaded = true;">;
    <br _moz_dirty="">
    <br _moz_dirty="">

As you can see, there is an iframe involved in the code.

The problem that needed to be solved

While automating the “write” into the text area of the RTE, the xpath was not being recognized. It took me a while to figure out the catch¬† being the iframe.

The “fix”

The script needs to specifically step into the iframe, address the “write” and then to manipulate any other action outside the iframe, the script needs to select the main window with the select window “null” which is to select the active window.

Here is a front end automation  script in java

package com.example.tests;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;

public class Untitled extends SeleneseTestCase {
public void setUp() throws Exception {
 selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.yelp.com/");

public void testUntitled() throws Exception {
 selenium.typeKeys("xpath=//body", "Yipee! Dude this works!!");
 selenium.clickAt("xpath=//*[@id=\"blog_title\"]", "");
 selenium.typeKeys("xpath=//*[@id=\"blog_title\"]", "blog");

public void tearDown() throws Exception {

as you can see from the scripts:

selenium.typeKeys("xpath=//body", "Huh");

Steps into by the select frame command, types in with the typeKeys and then selects the active window with the select window “null”

In case you are wondering, I did a quick short script with Selenium IDE, which generates code in Selenese and did a quick translate to java. Go ahead copy paste it, and try it out. Have any more nifty tricks with selenium drop me a note!