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 如下所示 −

Alert Test

廣告