当前位置: 首页 > 面试题库 >

使用webdriver与可爱的编辑器进行交互

农星华
2023-03-14
问题内容

有谁知道我如何使用webdriver与可爱的编辑器进行交互。我想清除文字吗?

 <iframe id="CE_Editor1_ID_Frame" src="cuteeditor_files/template.asp"
 frameborder="0" class="CuteEditorFrame CuteEditorFrame"
 style="background-color: white; border: 1px solid rgb(221, 221, 221);
 height: 100%; width: 100%; display: block;"></iframe>

下面的代码不起作用?

driver.switchTo().frame(0);
driver.switchTo().activeElement().clear();

问题答案:

我在http://cutesoft.net/example/general.aspx上查看了可爱编辑器的演示,现在我明白了为什么使用driver.switchTo().activeElement()iframe而不是查找textarea
/ input,因为iframe是’textarea’,并且您想要清除iframe中的所有内容。

我认为您的与演示类似

<iframe id="CE_Editor1_ID_Frame" src="cuteeditor_files/template.asp" frameborder="0" class="CuteEditorFrame CuteEditorFrame" style="background-color: white; border: 1px solid rgb(221, 221, 221); height: 100%; width: 100%; display: block;">
    <html>
        <head></head>
        <body>
            <table>the real stuff in the editor, you want to clear this, right?</table>
            <br>
            <br>
        </body>
    </html>
</iframe>

我认为Selenium没有提供任何删除节点的方法,但是您可以通过JavascriptExecutor来实现。 警告
:未经测试的代码,这里只有逻辑。您需要自己调试一下。

// first try to avoid switching frames by index, unless you have no other ways.

// if you have only one frame with class name CuteEditorFrame
WebElement editorFrame = driver.findElement(By.cssSelector(".CuteEditorFrame"));
driver.switchTo().frame(editorFrame);

// if the id 'CE_Editor1_ID_Frame' not dynamic
WebElement editorFrame = driver.findElement(By.cssSelector("#CE_Editor1_ID_Frame"));
driver.switchTo().frame(editorFrame); // driver.switchTo().frame("CE_Editor1_ID_Frame");

// then remove everything inside the iframe's body
JavascriptExecutor js;
if (driver instanceof JavascriptExecutor) {
    js = (JavascriptExecutor)driver;
}
WebElement editorBody = driver.findElement(By.cssSelector("body"));
js.executeScript("arguments[0].innerHTML = ''", editorBody);

// alternatively, using sendKeys directly is a better way
WebElement body = driver.findElement(By.tagName("body")); // then you find the body
body.sendKeys(Keys.CONTROL + "a"); // send 'ctrl+a' to select all
body.SendKeys("Some text");


 类似资料:
  • 我正在尝试编辑远程AmazonEC2Linux实例上的文件。我目前正在使用nano,但我非常想要一个图形文本编辑器。我有两个问题: 当我ssh时,我必须使用sudo来编辑这些服务器文件。 我只能用亚马逊给我的密钥登录。ndrew.pemec2-user@55.55.44.33 请帮忙!我不挑剔,只是任何图形文本编辑器,因为使用nano是一个巨大的痛苦。

  • 我正在使用iText向现有pdf文件添加文本。它适用于简单的pdf,但与AcroForms的pdf存在问题。 我的代码: 错误消息:“此文档在Adobe Acrobat Reader DC中启用了扩展功能。文档自创建以来已更改,扩展功能的使用不再可用。请与作者联系以获取此文档的原始版本。” 并且没有我想添加到文件中的文本 知道我错过了什么吗?

  • 问题内容: 在过去的两年中,我一直在编写Java,现在,我开始用python(另外)进行编写。 问题是,当我查看我的Python代码时,似乎有人试图将Java代码转换为python格式,但结果却很糟糕,因为- python不是Java。 关于如何摆脱“用Python编写Java”模式的任何技巧? 谢谢! 问题答案: 您可能会考虑将自己沉浸在Python范例中。最好的方法是首先了解他们的知识,然后通

  • 在我的应用程序中,所有的查询编辑器都是Ace编辑器,我需要使用WebDriver输入查询。我试过使用发送键,但似乎不起作用。有没有其他的方式我可以发送我的输入到Ace编辑器,从而自动化? 下面是我的HTML代码

  • 我使用数据编辑器。当我尝试编辑并将其发布到服务器时,该行不断消失。刷新页面后,我可以看到实际更新的数据。 这是我的代码片段。 下面是服务器端脚本返回的JSON数据: 这个错误的可能原因是什么?

  • 问题内容: 在启动Selenium客户端之前,有人知道Selenium(最好是WebDriver)是否能够与已经运行的浏览器进行通信并通过它运行吗? 我的意思是,如果Selenium能够在不使用Selenium Server的情况下与浏览器通信(例如,可能是手动启动的Internet Explorer)。 问题答案: 这是一个非常古老的功能请求:允许webdriver附加到正在运行的浏览器。因此正