我是 selenium webdriver 的新手,我想使用富文本编辑器输入 iframe,如下所示:
<iframe frameborder="0" aria-describedby="cke_24" title="Rich text editor, Post_description" src="" tabindex="-1" allowtransparency="true">
#document
<html dir="rtl" lang="ar" class="CSS1Compat" contenteditable="true">
<head></head>
<body spellcheck="false" class="cke_show_borders">
<p>
</p>
</body>
</html>
</iframe>
我用过这个:
WebDriver driver;
WebElement frame = driver.findElement(By.xpath("//iframe[@title = 'Rich text editor, Post_description']"));
driver.switchTo().frame(frame);
WebElement editable = driver.switchTo().activeElement();
editable.sendKeys(desc);
driver.switchTo().defaultContent();
但它什么也没做...它只输入白线...有什么帮助吗?
最佳答案
WebElement frame = driver.findElement(By.xpath("//iframe[@title = 'Rich text editor, Post_description']"));
driver.switchTo().frame(frame);
WebElement body = driver.findElement(By.tagName("body"));
body.sendKeys("Hello world");
driver.switchTo().defaultContent();
关于java - 如何使用 selenium (java) 在 iframe 中输入内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23594433/