I am using Webdriver in Java with Firefox 14.
My problem is that I can't seem to get webdriver to play nicely with CkEditor. I have looked for solutions but have been unable to get any working in either Firefox 13 or 14. These are the solutions that I have tried:
The normal sendKeys interction
textArea.sendKeys();
or
textArea.click();
textArea.sendKeys();
Result: This code wouldn't produce any text in the CkEditor
The code from Selenium issue 3890
d.get("http://ckeditor.com/demo");
WebElement iframe = d.findElement(By.tagName("iframe"));
d.switchTo().frame(iframe);
WebElement tinymce = d.findElement(By.tagName("body"));
tinymce.clear();
tinymce.sendKeys("Hello, ckeditor!");
Result: This code will go to the site and clear the editor, but won't put in any text into the CkEditor instance.
AdvancedUserInteractions -- eg. Actions() in multiple variations
textArea.click();
new Actions(driver).sendKeys("Hello, ckeditor!").build().perform();
and
new Actions(driver).sendKeys(textArea, "Hello, ckeditor!").build().perform();
and
new Actions(driver).click(textArea).sendKeys("Hello, ckeditor!").build().perform();
Result: These won't produce any text in the CkEditor
Switching iframes (as per Issue 3890 above) and using AdvancedUserInteractions
Code similar to:
driver.switchTo().frame(iframe);
textArea.click();
new Actions(driver).sendKeys("Hello, ckeditor!").build().perform();
Result: Throws error "c.value is undefined"
Using the Javascript and the CkEditor Api
JavascriptExecutor js = (JavascriptExecutor) d;
System.out.println("[debug] Set Text: " + setText);
js.executeScript("CKEDITOR.instances.editor1.setData('<p> "+ setText +"</p>');");
Result: Excludes the '/' character when "org.apache.commons.lang.StringEscapeUtils.escapeHtml" is/isn't used to convert "setText" to Html entries. This solution also throws an "ERROR: null" on large strings.
Any ideas on things that I haven't tried? Fixes for things I have tried? Any other suggestions?
Thanks!
Sometimes Text areas are handled as Iframe where you have to switch to that frame and run JS command to type on it .
final WebDriver frame = driver.switchTo().frame(findElement(By.id("locator")); //any locator
((JavascriptExecutor) driver).executeScript("document.body.innerHTML='" + TestValueThatYouWantToType + "'");
driver.switchTo().defaultContent();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With