开发者

How to send text to a CKEditor WYSIWYG editor box using Watir-WebDriver

开发者 https://www.devze.com 2023-03-27 15:29 出处:网络
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

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 e开发者_Python百科nsure 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)


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.


Thanks to Jari's pointer, I ended up executing javascript to update the field reliably:

b.execute_script "CKEDITOR.instances.editor1.setData( 'hello' );"


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

0

精彩评论

暂无评论...
验证码 换一张
取 消