Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using Selenium Webdriver with CkEditor in Firefox 14

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:

  1. The normal sendKeys interction

    textArea.sendKeys();
    

    or

    textArea.click();
    textArea.sendKeys();
    

    Result: This code wouldn't produce any text in the CkEditor

  2. 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.

  3. 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

  4. 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"

  5. 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!

like image 587
Troy Avatar asked Oct 22 '22 12:10

Troy


1 Answers

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();
like image 87
Reaz Patwary Avatar answered Jan 02 '23 20:01

Reaz Patwary