简体   繁体   中英

How to type in iframe using selenium2 (java)?

I'm new in selenium webdriver & I want to type in iframe with Rich text editor like this :

<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>

I used this :

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

But it does nothing... It only types white lines... Any help?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM