Dec 09
18
Simulating typing into a GWT RichTextArea with Selenium 2 (WebDriver)
Leave a comment »
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:
- Select the iframe that the RichTextArea resides in
- Type the required text into the body of the iframe
- 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!