如何使用 Watir-WebDriver 将文本发送到 CKEditor WYSIWYG 编辑器框
我有一个 watir-webdriver 脚本,它使用下面的代码设置 CKEditor 框,但这仅适用于 Mac OSX 上的 Firefox,当我专注于屏幕时。例如,如果我集中注意力并让此脚本在后台运行,则不会输入文本(但不会引发异常或错误)。
有人知道如何始终确保它已设置吗?
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 在 Mac OSX 上运行正常,但我也想在 Firefox 上运行测试)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Firefox 不会调度焦点/模糊事件,除非它位于前台。最可靠的解决方案是始终确保每个浏览器实例有单独的显示(或虚拟机)。如果失败,您可以使用 Browser#execute_script 设置编辑器的值。
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.
感谢 Jari 的指针,我最终执行了 javascript 来可靠地更新该字段:
Thanks to Jari's pointer, I ended up executing javascript to update the field reliably:
试试这个:
它适用于我的 OSX 和 FF3.6
Try this:
it works for me on OSX and FF3.6