niazi niazi - 4 months ago 30
Java Question

After sending text to ckeditor it does not recognize next element (selenium)

i successfully send text to

ckeditor
through these command

WebElement iframe = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(iframe);
WebElement tinymce = driver.findElement(By.tagName("body"));
tinymce.clear();
tinymce.sendKeys("Automation Description");


Problem

Text "Automation Description" is succesfully passed to
ckeditor
.
But. it does not locate the next element
Following error is displayed


no such element: Unable to locate element:
{"method":"xpath","selector":".//*[@id='select2-state_name-container']"}


When I added Block Comment to

WebElement iframe = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(iframe);
WebElement tinymce = driver.findElement(By.tagName("body"));
tinymce.clear();
tinymce.sendKeys("Automation Description");


It successful located the next element.

Help me to add a command so that I can locate next element after texting text to ckeditor. Thank you




Here's a screen shot:

screen shot

Answer

As I seeing your code you are going to switch frame first then find ckeditor and set value. But you didn't switch back to default content to find the next element that's why selenium searching the locator into already switched frame where element is not present actually, So you should try to switch back before finding element as below :-

WebElement iframe = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(iframe);
WebElement tinymce = driver.findElement(By.tagName("body"));
tinymce.clear();
tinymce.sendKeys("Automation Description");

//Now switch back first to default 
driver.switchTo().defaultContent();

 //Now you can go to find next element 

Hope it helps...:)