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......>
  <html>
   <head> ............
   </head>;
   <body onload="document.body._rteLoaded = true;">;
    <br _moz_dirty="">
    <br _moz_dirty="">
   </body>
  </html>
 </iframe>

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 {
@Before
public void setUp() throws Exception {
 selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.yelp.com/");
 selenium.start();
}

@Test
public void testUntitled() throws Exception {
 selenium.open("http://shine.yahoo.com/write");
 selenium.waitForPageToLoad("");
 selenium.selectFrame("xpath=//*[@id=\"editor_editor\"]");
 selenium.typeKeys("xpath=//body", "Yipee! Dude this works!!");
 selenium.selectWindow("");
 selenium.clickAt("xpath=//*[@id=\"blog_title\"]", "");
 selenium.typeKeys("xpath=//*[@id=\"blog_title\"]", "blog");
}

@After
public void tearDown() throws Exception {
 selenium.stop();
 }
}

as you can see from the scripts:

selenium.selectFrame("xpath=//*[@id=\"editor_editor\"]");
selenium.typeKeys("xpath=//body", "Huh");
selenium.selectWindow("");

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!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s