aboutsummaryrefslogtreecommitdiffstats
path: root/testbench-api/src/main/java/com/vaadin/testbench/elements/RichTextAreaElement.java
diff options
context:
space:
mode:
Diffstat (limited to 'testbench-api/src/main/java/com/vaadin/testbench/elements/RichTextAreaElement.java')
-rw-r--r--testbench-api/src/main/java/com/vaadin/testbench/elements/RichTextAreaElement.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/RichTextAreaElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/RichTextAreaElement.java
index 2728468a3e..d6ce571f01 100644
--- a/testbench-api/src/main/java/com/vaadin/testbench/elements/RichTextAreaElement.java
+++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/RichTextAreaElement.java
@@ -15,6 +15,7 @@
*/
package com.vaadin.testbench.elements;
+import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import com.vaadin.testbench.By;
@@ -33,4 +34,44 @@ public class RichTextAreaElement extends AbstractFieldElement {
public WebElement getEditorIframe() {
return findElement(By.tagName("iframe"));
}
+
+ /**
+ * Return value of the field element.
+ *
+ * @return value of the field element
+ * @since
+ */
+ public String getValue() {
+ JavascriptExecutor executor = (JavascriptExecutor) getDriver();
+ return executor.executeScript(
+ "return arguments[0].contentDocument.body.innerHTML",
+ getEditorIframe()).toString();
+ }
+
+ /**
+ * Set value of the field element.
+ *
+ * @param chars
+ * new value of the field
+ * @since
+ */
+ public void setValue(CharSequence chars) throws ReadOnlyException {
+ if (isReadOnly()) {
+ throw new ReadOnlyException();
+ }
+ JavascriptExecutor executor = (JavascriptExecutor) getDriver();
+ executor.executeScript("var bodyE=arguments[0].contentDocument.body;\n"
+ + "bodyE.innerHTML=arguments[1]; \n"
+ + "var ev = document.createEvent('HTMLEvents');\n"
+ + "ev.initEvent('change', true, false); \n"
+ + "bodyE.dispatchEvent(ev);", getEditorIframe(), chars);
+ }
+
+ @Override
+ public void focus() {
+ waitForVaadin();
+ JavascriptExecutor executor = (JavascriptExecutor) getDriver();
+ executor.executeScript("arguments[0].contentDocument.body.focus();",
+ getEditorIframe());
+ }
}