问题
I have a watir-webdriver script that sets a CKEditor box using the code below, but this only works with Firefox on Mac OSX when I focus on the screen. For example, if I focus away and let this script run in the background, the text is not entered (but no exception or error is raised).
Anyone know how to always ensure it is set?
require "watir-webdriver"
b = Watir::Browser.new :firefox
b.goto "http://ckeditor.com/demo"
b.frame(:title => 'Rich text editor, editor1, press ALT 0 for help.').send_keys "hello world"
(Google Chrome works ok on Mac OSX, but I would like to run my tests against Firefox too)
回答1:
Firefox doesn't dispatch focus/blur events unless it is in the foreground. The most reliable solution is to always ensure a separate display (or VM) per browser instance. Failing that you may be able to use set the editor's value using Browser#execute_script.
回答2:
Thanks to Jari's pointer, I ended up executing javascript to update the field reliably:
b.execute_script "CKEDITOR.instances.editor1.setData( 'hello' );"
回答3:
Try this:
b.frame(:title => 'Rich text editor, editor1, press ALT 0 for help.').body.send_keys "hello world"
it works for me on OSX and FF3.6
来源:https://stackoverflow.com/questions/7025823/how-to-send-text-to-a-ckeditor-wysiwyg-editor-box-using-watir-webdriver