如何在 iframe 中的富文本编辑器中使用 SendKeys(webdriver) 命令 [英] How to use SendKeys(webdriver) command in Rich Text editor that is located in iframe

查看:27
本文介绍了如何在 iframe 中的富文本编辑器中使用 SendKeys(webdriver) 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临以下问题.我无法在带有文本编辑器的 iframe 中输入文本:这是 html:

I'm facing the following problem.I can not type text in iframe in which there is a text editor:Here is the html:

<iframe class="cke_wysiwyg_frame cke_reset" frameborder="0" style="width: 100%;  height: 100%;" aria-describedby="cke_39" title="Текстов редактор за форматиран текст,description1" src="" tabindex="0" allowtransparency="true">
<!DOCTYPE html>
<html lang="bg" dir="ltr">
<head>
<body class="cke_editable cke_editable_themed cke_contents_ltr" contenteditable="true" spellcheck="false">
<p>
<br>
</p>
</body>
</html>
</iframe>

这是我到目前为止所做的,但测试成功通过,文本编辑器中没有写入任何文本.可能解决方案是使用 Javascript 执行器,但我不熟悉它.

Here is what I have done so far,but the test passed successfully and no text is writen in the text editor.May be the solution is with Javascript executor but I'm not familiar with it.

WaitTool.waitForElementPresent(Browser.instance, By.tagName("iframe"), 10);
WebElement iframe = Browser.instance.findElement(By.tagName("iframe"));
Browser.instance.switchTo().frame(iframe);
WebElement description=Browser.instance.findElement(By.xpath("//body[@class='cke_editable cke_editable_themed cke_contents_ltr']"));
description.click();
description.sendKeys("someText");
Browser.instance.switchTo().defaultContent();

提前致谢!

推荐答案

有多种方法可以做到.这是一篇您可能想看的文章.

There are multiple ways of doing it. Here's an article you might want to have a look.

使用 Selenium WebDriver 测试 WYSIWYG 编辑器

  • 直接发送密钥

这种方法是您尝试过但没有奏效的方法.请尝试确保