使用webdriver,ruby和变量将文本输入tinymce

时间:2021-12-07 20:28:17

I'm using webdriver and Ruby...

我正在使用webdriver和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.

所以我能够使用下面的脚本将文本写入tinymce字段。但是在最后一行,driver.execute ...我想将静态值'bob'更改为传递的变量parValue的值。我尝试了对driver.execute_script行的一些修改,但我仍然遇到错误。换句话说,我不知道javascript,我无法找到这样做的方法。

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'?

我已经尝试替换代码并使用sendkeys,但这不会打印任何东西到我的tinymce框。有没有办法使用从parValue传入的值并替换'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

1 个解决方案

#1


0  

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:

这看起来很简单,所以我担心我可能会误解,但你可以使用ruby的字符串插值来代替bob与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

#1


0  

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:

这看起来很简单,所以我担心我可能会误解,但你可以使用ruby的字符串插值来代替bob与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