javascript - How to use sendKeys into ckeditor text area using java selenium -


how can send keys reach text area in java selenium.

here html code include iframe:

<div class="col-sm-11"> <textarea class="ckeditor ng-untouched ng-empty ng-invalid ng-invalid-required ng-dirty ng-valid-parse" ng-class="{true:'validation-error'}[submitted]" placeholder="enter text ..." ck-editor="" ng-model="newticket.message" name="message" style="visibility: hidden; display: none;" aria-invalid="true"/> <div id="cke_message" class="cke_1 cke cke_reset cke_chrome cke_editor_message cke_ltr cke_browser_gecko" lang="en" aria-labelledby="cke_message_arialbl" role="application" dir="ltr"> <span id="cke_message_arialbl" class="cke_voice_label">rich text editor, message</span> <div class="cke_inner cke_reset" role="presentation"> <span id="cke_1_top" class="cke_top cke_reset_all" style="height: auto; -moz-user-select: none;" role="presentation"> <div id="cke_1_contents" class="cke_contents cke_reset" role="presentation" style="height: 200px;"> <span id="cke_50" class="cke_voice_label">press alt 0 help</span> <iframe class="cke_wysiwyg_frame cke_reset" frameborder="0" src="" style="width: 100%; height: 100%;" title="rich text editor, message" aria-describedby="cke_50" tabindex="0" allowtransparency="true"/> </div> </div> </div> <span class="ng-binding ng-hide" style="color:red" ng-show="newticketform.message.$invalid && submitted" aria-hidden="true">content required</span> </div> 

i try use below method using iframe class name couldn’t send data it. here selenium code

for (string handle002 : driver.getwindowhandles())      {         driver.switchto().window(handle002);         thread.sleep(500);           (string handle001 : driver.getwindowhandles())              {     driver.switchto().window(handle001);     thread.sleep(500);   driver.switchto().frame(driver.findelement(by.classname("cke_wysiwyg_frame cke_reset")));   driver.switchto().defaultcontent();   webelement body=driver.findelement(by.classname("cke_wysiwyg_frame cke_reset"));   body.sendkeys("test");   driver.switchto().defaultcontent();             }     } 

enter image description here

i have got solution after seeing provided html, should try using webdriverwait below :-

webdriverwait wait = new webdriverwait(driver, 10);  wait.until(expectedconditions.frametobeavailableandswitchtoit(by.cssselector("iframe.cke_wysiwyg_frame.cke_reset")));  webelement body = wait.until(expectedconditions.visibilityofelementlocated(by.tagname("body"))); body.sendkeys("test string");  //now after entering text texteditor switch default content  driver.switchto().defaultcontent(); 

Comments