Simulating Typing into a GWT RichTextArea with Selenium 2 (WebDriver)

I wrote an entry previously about manipulating a GWT RichTextArea widget via Selenium. Recently I've been investigating moving to Selenium 2, also known as Selenium WebDriver.

As with Selenium 1 the mechanism for manipulating a RichTextArea widget in Selenium 2:

  1. Select the iframe that the RichTextArea resides in
  2. Type the required text into the body of the iframe
  3. Select the top level frame

Assuming a RichTextArea with an ID of "gwt-debug-text-editor" the following Java code fragment gives a concrete example of doing this

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
...
private final WebDriver webDriver;
...
public void typeIntoRichTextArea()
{
    final WebDriver frame = webDriver.switchTo().frame("gwt-debug-text-editor");
    final WebElement editorBody = frame.findElement(By.xpath("//*"));
    editorBody.sendKeys("This is some example text to type into the text area");
    webDriver.switchTo().defaultContent();
}

you should now see text in your rich text editor!

This site uses cookies. Continue to use the site as normal if you are happy with this, or read more about cookies and how to manage them.

X