How to use SendKeys (webdriver) command in Rich Text editor that is located in iframe

0 votes

I'm facing the following problem. I am not able to type text in iframe in which there is a text editor: Below is theHTML code:

<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">
<body class="cke_editable cke_editable_themed cke_contents_ltr" contenteditable="true" spellcheck="false">

My test passed successfully and no text is written in the text editor:

WaitTool.waitForElementPresent(Browser.instance, By.tagName("iframe"), 10);
WebElement iframe = Browser.instance.findElement(By.tagName("iframe"));
WebElement description=Browser.instance.findElement(By.xpath("//body[@class='cke_editable cke_editable_themed cke_contents_ltr']"));;
Aug 23, 2018 in Selenium by Atul
• 10,200 points

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Send keys directly is the approach that you have tried but it did not work. Please  make sure your locators to <iframe> and <body> are correct. Otherwise, I'd suggest using JavaScriptExecutor for more stable solutions.

Set innerHTML

WaitTool.waitForElementPresent(Browser.instance, By.className("cke_wysiwyg_frame"), 10);
WebElement iframe = Browser.instance.findElement(By.className("cke_wysiwyg_frame"));

WebElement description = Browser.instance.findElement(By.cssSelector("body"));
(JavascriptExecutor)Browser.instance.executeScript("arguments[0].innerHTML = '<h1>Set text using innerHTML</h1>'", description);

Use CKEditor's native API

// no need to switch iframe
(JavascriptExecutor)Browser.instance.executeScript("CKEDITOR.instances.ckeditor.setData('<h1>Native API text</h1> Editor')");
answered Aug 23, 2018 by Meci Matt
• 9,400 points

Related Questions In Selenium

0 votes
1 answer

Can anyone help me that how to run Selenium WebDriver test cases in Chrome?

Download the executable driver from: ChromeDriver Download Before ...READ MORE

answered Mar 29, 2018 in Selenium by nsv999
• 5,030 points
0 votes
1 answer

How to use Actions class in Selenium Webdriver?

In seleniun webdriver it is not mandatory ...READ MORE

answered Apr 4, 2018 in Selenium by Damon Salvatore
• 5,250 points
0 votes
1 answer

How to choose the correct iframe in Selenium WebDriver?

When I checked the website you've mentioned, ...READ MORE

answered Apr 29, 2018 in Selenium by king_kenny
• 3,590 points
0 votes
1 answer

How to use webdriver in selenium?

In Java, in order to call the ...READ MORE

answered Dec 20, 2018 in Selenium by Shuvodip
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,030 points
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
0 votes
1 answer
0 votes
1 answer

How to wait till the text is present In text field

Use Waits in Selenium WebDriver to wait ...READ MORE

answered Jul 5, 2018 in Selenium by Meci Matt
• 9,400 points

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.