- Watir Tutorial
- Watir - Home
- Watir - Overview
- Watir - Introduction
- Watir - Environment Setup
- Watir - Installing Drivers for Browsers
- Watir - Working with Browsers
- Watir - Web Elements
- Watir - Locating Web Elements
- Watir - Working with Iframes
- Watir - Automatic Waits
- Watir - Headless Testing
- Watir - Mobile Testing
- Watir - Capturing Screenshots
- Watir - Page Objects
- Watir - Page Performance
- Watir - Cookies
- Watir - Proxies
- Watir - Alerts
- Watir - Downloads
- Watir - Browser Windows
- Watir Useful Resources
- Watir - Quick Guide
- Watir - Useful Resources
- Watir - Discussion
Watir - Alerts
In this chapter we will understand how to handle alerts using Watir.
Syntax
browser.alert.exists? browser.alert.ok browser.alert.close
Testpage
<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 Code
require 'watir' b = Watir::Browser.new :chrome b.goto('http://localhost/uitesting/testalert.html') b.button(id: 'btnsubmit').click b.alert.ok b.screenshot.save 'alerttest.png'
The output alerttest.png is shown here −
Advertisements
To Continue Learning Please Login
Login with Google