如何使用selenium2(java)输入iframe?

时间:2014-05-11 15:24:58

标签: java selenium selenium-webdriver webdriver

我是selenium webdriver&的新成员。我想用Rich文本编辑器输入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();

但它什么也没做......它只是输入白线......有什么帮助吗?

1 个答案:

答案 0 :(得分:1)

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();