在Firefox 14中使用Selenium Webdriver与CkEditor

5
我正在使用Java中的Webdriver和Firefox 14。
我的问题是,我似乎无法使webdriver与CkEditor良好地配合使用。我已经寻找了解决方案,但在Firefox 13或14中均无法使其正常工作。这些是我尝试过的解决方案:
  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.

有没有我没尝试过的想法?对我尝试过的事情进行修复的方法?还有其他建议吗?
谢谢!
3个回答

3
有时文本区域被视为Iframe,您需要切换到该框架并运行JS命令才能在其中输入。
final WebDriver frame = driver.switchTo().frame(findElement(By.id("locator")); //any locator
    ((JavascriptExecutor) driver).executeScript("document.body.innerHTML='" + TestValueThatYouWantToType + "'");
    driver.switchTo().defaultContent();

0

0
只需在tinymce.clear();后添加等待语句,它就可以正常工作了。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接