您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Watir
Watir Webdriver 對JS Dialog的處理
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2013/12/30 13:25:11 ] 推薦標(biāo)簽:Watir 功能測試

Watir webdriver內(nèi)置了如何處理javascript. dialog的方法,以及從dialog獲得所需值的方法。

# 判斷alert是否存在
browser.alert.exists?
 
# 獲得alert的值
browser.alert.text
 
# 關(guān)閉alert
browser.alert.ok
browser.alert.close

# 接受confirm
browser.alert.ok
 
# 取消confirm
browser.alert.close

# 輸入內(nèi)容到prompt
browser.alert.set "Prompt answer"
 
# 接受prompt
browser.alert.ok
 
# 取消prompt
browser.alert.close

如果上述方法無效,我們還有一些替代的方法:

# 對于alert,overide從而使其不返回任何值
browser.execute_script("window.alert = function() {}")
 
# 返回用戶在prompt輸入的值
browser.execute_script("window.prompt = function() {return 'my name'}")
 
# 返回空值,用于模擬點(diǎn)擊prompt的cancel
browser.execute_script("window.prompt = function() {return null}")
 
# 返回true,用于模擬模擬點(diǎn)擊confirm的ok
browser.execute_script("window.confirm = function() {return true}")
 
# 返回false,用于模擬點(diǎn)擊confirm的cancel
browser.execute_script("window.confirm = function() {return false}")
 
# 對于離開popup不返回任何值
browser.execute_script("window.onbeforeunload = null")

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