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,240 points

1 answer to this question.

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,460 points

Related Questions In Selenium

0 votes
1 answer
0 votes
2 answers

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

You first need to download chrome driver ...READ MORE

answered Aug 26, 2019 in Selenium by Abha
• 27,930 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,540 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,710 points
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,510 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,890 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,890 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,460 points