Watir Webdriver的editor处理

上一篇 / 下一篇  2013-01-28 15:00:47 / 个人分类:测试

很多网站使用了WYSIWYG Editor来输入文本,比如51testing这样的。Watir内置了一些方法可以对其进行处理:

一种是先查找到editor所在的iframe,然后使用send_keys的方法来发送字符串,需要注意的是,包含该iframe的窗口必须是在所有的窗口最上方.

另外一种方式是书写一段javascript语句,通过对browser进行内容输入,这种方法最常见

例如CKEditor

require 'watir-webdriver'
b = Watir::Browser.new :firefox
b.goto 'http://ckeditor.com/demo'
b.execute_script("CKEDITOR.instances['editor1'].setData('hello world');")
b.frame(:title => 'Rich text editor, editor1, press ALT 0 for help.').send_keys 'hello world again'

这个例子就是向iframe直接通过send_keys发送字符

而使用TinyMCE Editor的例子,就是执行一段javascript语句

require 'watir-webdriver'
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'


TAG:

 

评分:0

我来说两句

日历

« 2024-04-30  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 151396
  • 日志数: 185
  • 文件数: 6
  • 建立时间: 2007-08-06
  • 更新时间: 2015-01-06

RSS订阅

Open Toolbar