2011-08-11 23 views
3

我有一個使用下面的代碼設置CKEditor框的watir-webdriver腳本,但是這隻適用於Mac OSX上的Firefox,當我專注於屏幕時。例如,如果我關注並讓該腳本在後臺運行,則不會輸入文本(但不會引發異常或錯誤)。如何使用Watir-WebDriver發送文本到CKEditor WYSIWYG編輯框

任何人都知道如何始終確保它被設置?

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" 

(谷歌瀏覽器在Mac OSX確定,但我想對Firefox的運行我測試過)

回答

1

感謝傑瑞的指針,我結束了執行JavaScript更新可靠的領域:

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

Firefox不派遣焦點/模糊的事件,除非它是在前臺。最可靠的解決方案是始終確保每個瀏覽器實例都有單獨的顯示(或VM)。如果你沒有能夠使用Browser#execute_script設置編輯器的值。

+0

謝謝,我已成功使用browser.execute_script(「CKEDITOR.instances.editor1.setData('hello');」) –

-1

試試這個:

b.frame(:title => 'Rich text editor, editor1, press ALT 0 for help.').body.send_keys "hello world" 

它爲我工作在OSX和FF3.6

+1

如果Firefox不在焦點 –

相關問題