Olivier
Olivier

Reputation: 117

Get the value from a RichTextArea in a Selenium test

I'm trying to test with Selenium if a value has been loaded from the server in a RichTextArea in GWT.

I'm doing

@FindByDebugId("gwt-debug-about-me")
private WebElement aboutMeRichText;

When I send keys, there's no problem, the text is printed in the RichTextArea.

But when I try this (retrieve the value):

aboutMeRichText.getText() 

it returns an empty String.

When I look at what's generated in the HTML, it's something like that :

<iframe class="GJUJXOPBLP-com-asdf-asdf-client-resource-Resources-Styles-textBox hasRichTextToolbar" id="gwt-debug-about-me">
#document
<html><head></head><body>Hi there !</body></html>
</iframe>

How should I do to retrieve the "Hi there !" text?

Upvotes: 0

Views: 454

Answers (1)

Yi Zeng
Yi Zeng

Reputation: 32855

It's an iframe, which is not the same with normal WebElement, so you need to switch to it first.

driver.switchTo().frame(aboutMeRichText);
WebElement body = driver.findElement(By.TagName("body")); // then you find the body
body.getText();

// get out of the editor
driver.switchTo().defaultContent();

Upvotes: 1

Related Questions