Question

I'm using webdriver and Ruby...

So I was able to write text into a tinymce field using the script below. However on the last line, driver.execute... I would like to change the static value 'bob' to be the value of the variable being passed, parValue. I've tried few modifications to the driver.execute_script line, but I continue to get errors. In other words, I don't know javascript and I am unable to find a way to do this.

I've tried replacing the code and use sendkeys, but that does not print anything to my tinymce box. Is there a way to use the value being passed in from parValue and replace 'bob'?

def enterValues(driver,parField,parValue)
  tinymce_frame = driver.find_element(:id => parField)
  driver.switch_to.default_content
  driver.switch_to.frame(tinymce_frame)     
  editor_body = driver.find_element(:tag_name => 'body')
  driver.execute_script("arguments[0].innerHTML = 'bob'", editor_body)

end
Was it helpful?

Solution

this seems kind of simple so I'm worried I might be misunderstanding but you could use ruby's string interpolation to replace bob with parvalue:

def enterValues(driver,parField,parValue)
  tinymce_frame = driver.find_element(:id => parField)
  driver.switch_to.default_content
  driver.switch_to.frame(tinymce_frame)     
  editor_body = driver.find_element(:tag_name => 'body')
  driver.execute_script("arguments[0].innerHTML = '#{parValue}'", editor_body)

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