Question

Maybe I'm just missing something but I'm trying to use webdriver and Ruby to enter text into a WYSIWYG. I don't receive any errors but text does not get entered as well.

Here is my code that I wrote

  tinymce_frame = driver.find_element(:id => "Speakers_ifr")
  driver.switch_to.frame(tinymce_frame)
  editor_body = driver.find_element(:css => 'body')
     #I also tried replacing 'body' with the line of code below
     #editor_body = driver.find_element(:css => "html body#tinymce.mceContentBody")

  editor_body.send_keys("BOB")

Here is the HTML from Firebug

<iframe id="Speakers_ifr" frameborder="0" src="javascript:""" allowtransparency="true" title="Rich Text AreaPress ALT-F10 for toolbar. Press ALT-0 for help" style="width: 100%; height: 256px; display: block;">
<!DOCTYPE >
<html>
   <head xmlns="http://www.w3.org/1999/xhtml">
   <body id="tinymce" class="mceContentBody " contenteditable="true"   onload="window.parent.tinyMCE.get('Speakers').onLoad.dispatch();" spellcheck="false"   dir="ltr">
     <br data-mce-bogus="1">
  </body>

Thanks for any suggestions. Scott

Was it helpful?

Solution

I just needed to add a couple of lines of code.

  tinymce_frame = driver.find_element(:id =>  "Speakers_ifr")
  driver.switch_to.default_content  # Added this line
  driver.switch_to.frame(tinymce_frame)     
  editor_body = driver.find_element(:tag_name => 'body')
  driver.execute_script("arguments[0].innerHTML = 'bob'", editor_body) #Added this line

My next challenge is trying to make 'bob' a variable that is being passed into the function. I'll write that up as another question, if I cannot find it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top