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