- Watir 教程
- Watir - 主頁
- Watir - 概覽
- Watir - 簡介
- Watir - 環境設定
- Watir - 安裝瀏覽器驅動程式
- Watir - 使用瀏覽器
- Watir - 網頁元素
- Watir - 定位網頁元素
- Watir - 使用 Iframe
- Watir - 自動等待
- Watir - 無頭測試
- Watir - 移動測試
- Watir - 捕獲螢幕截圖
- Watir - 頁面物件
- Watir - 頁面效能
- Watir - Cookie
- Watir - 代理
- Watir - 警告
- Watir - 下載
- Watir - 瀏覽器視窗
- Watir 實用資源
- Watir - 快速指南
- Watir - 實用資源
- Watir - 討論
Watir - 警告
本章中我們將瞭解如何使用 Watir 處理警告。
語法
browser.alert.exists? browser.alert.ok browser.alert.close
測試頁
<html>
<head>
<title>Testing Alerts Using Watir</title>
</head>
<body>
<script type = "text/javascript">
function wsformsubmitted() {
alert("Button is Clicked !");
}
</script>
<button id = "btnsubmit" onclick = "wsformsubmitted();">Submit</button>
</body>
</html>
Watir 程式碼
require 'watir'
b = Watir::Browser.new :chrome
b.goto('https:///uitesting/testalert.html')
b.button(id: 'btnsubmit').click
b.alert.ok
b.screenshot.save 'alerttest.png'
輸出 alerttest.png 如下所示 −
廣告