所见即所得编辑器  

使用 Watir 在所见即所得编辑器中输入文本的推荐方法是找到 iFrame,然后找到并使用 #send_keys 方法。

或者,您可以在浏览器对象上执行 JavaScript,该对象设置所见即所得编辑器的值。

CKEditor

推荐

b = Watir::Browser.new
b.goto 'http://nightly.ckeditor.com/18-08-02-06-04/standard/samples/'
b.iframe.body.wd.clear
b.iframe.body.send_keys "foo"

请注意,此示例不再起作用。如果有人有可行示例,请更新此代码

b = Watir::Browser.new :firefox
b.goto 'http://nightly.ckeditor.com/18-08-02-06-04/standard/samples/'
b.execute_script("CKEDITOR.instances['editor1'].setData('hello world');")
f = b.frame(title: 'Rich text editor, editor1, press ALT 0 for help.')
f.send_keys 'hello world again'

TinyMCE 编辑器

推荐

b = Watir::Browser.new
b.goto 'http://tinymce.moxiecode.com/tryit/full.php'
f = b.iframe(id: 'cp_embed_NGegZK').iframe(id: 'result-iframe')
wysiwg = f.iframe.body
wysiwg.wd.clear
wysiwg.send_keys "hello world"

请注意,此示例不再起作用。如果有人有可行示例,请更新此代码

b = Watir::Browser.new
b.goto 'http://tinymce.moxiecode.com/tryit/full.php'
b.execute_script("tinyMCE.get('content').execCommand('mceSetContent',false, 'hello world' );")
b.frame(id: 'content_ifr').send_keys 'hello world again'

上次更新:2018 年 8 月 2 日