SanjayDVG
SanjayDVG

Reputation: 387

Locating CK Editor and Sending text to it in Selenium Webdriver

Hi I am trying to locate CK editor for my project through Selenium Webdriver code(Java). But Whenever I try to use SendKeys() method it is not working for me. Below is the screenshot of CK Editor and HTML code.

enter image description here

And below is the code,

if(driver.findElement(By.cssSelector("iframe#scayt_8")).isEnabled())
{
  WebElement iframe = driver.findElement(By.cssSelector("iframe#scayt_8"));  
  System.out.println("Frame Enabled");
  if(driver.findElement(By.xpath("//iframe[@id = 'scayt_8']")).isDisplayed())           
  {           
    System.out.println("Frame Displayed");
    driver.switchTo().frame(iframe);
    iframe.clear();
    System.out.println("Clicking frame");
    iframe.click();
    iframe.sendKeys("Hello!!");
  }
}

Please help me to locate CK Editor and to Send text to it.

Upvotes: 2

Views: 6380

Answers (4)

Easir Arafat
Easir Arafat

Reputation: 11

WebElement iframe = driver.findElement(By.tagName("iframe")); driver.switchTo().frame(iframe); 
WebElement tinymce = driver.findElement(By.tagName("body")); 
tinymce.clear(); 
tinymce.sendKeys("Hello, ckeditor!");;


This will help you to send text in CKeditor. Try this. It will work

Upvotes: 0

Alex Collins
Alex Collins

Reputation: 1016

You probably need to switch to the inline frame to locate it.

WebElement editorFrame = driver.findElement(By.id("scayt_8"));

driver.switchTo().frame(editorFrame);

WebElement body = driver.findElement(By.tagName("body"));

body.clear(); 
body.sendKeys("some text");

We provide techniques for working with editors in chapter 3 of our book Selenium WebDriver In Practice.

Upvotes: 7

Vishal Jagtap
Vishal Jagtap

Reputation: 896

Once you switch to iframe, try to locate webelement by paragraph tag name inside iframe, something like below:-

 WebElement body=driver.findElement(By.tagName("p"));

Then try to send keys using this webelement:

body.sendKeys("Hello!!");

Upvotes: 0

vkate
vkate

Reputation: 1

I think iframe is being searched based on cssSelector but i think it is supposed to be based on id? which is scayt_8. Can you try with following code to fetch iframe instead of cssSelector:

driver.FindElement(By.TagName("iframe"))

Upvotes: 0

Related Questions