您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Watir
Watir Webdriver的editor處理
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2014/2/17 10:38:12 ] 推薦標(biāo)簽:Watir Webdriver

很多網(wǎng)站使用了WYSIWYG Editor來輸入文本。Watir內(nèi)置了一些方法可以對其進(jìn)行處理:

一種是先查找到editor所在的iframe,然后使用send_keys的方法來發(fā)送字符串,需要注意的是,包含該iframe的窗口必須是在所有的窗口上方.

另外一種方式是書寫一段javascript語句,通過對browser進(jìn)行內(nèi)容輸入,這種方法常見

例如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'

這個(gè)例子是向iframe直接通過send_keys發(fā)送字符

而使用TinyMCE Editor的例子,是執(zhí)行一段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'

軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd