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://127.0.0.1/uitesting/testalert.html')
b.button(id: 'btnsubmit').click
b.alert.ok
b.screenshot.save 'alerttest.png'

输出 alerttest.png 如下所示 −

Alert Test

广告