- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to handle web based alerts in Selenium?
Selenium WebDriver gives multiple APIs to handle pop ups or alerts with the help of Alert interface.
dismiss()
This will cancel the button for alert.
accept()
This will accept the button for alert.
getText()
This will extract the text on alert.
sendKeys()
This will enter text on the alert box.
Example
Syntax with code snippet −
// Alert Alert a = driver.switchTo().alert(); // Extract alert message. String msg= driver.switchTo().alert().getText(); // print the message on console System.out.println(msg); // entering text on alert box a .sendkeys(“Testing”); // alert accept a.accept() // alert dismiss a.dismiss()
- Related Articles
- How to Handle alerts in Selenium?
- How will you handle alerts in Selenium with python?
- Can selenium handle Windows based pop up?
- Is it possible to handle Windows based pop-ups in Selenium?
- How to handle frames in Selenium?
- How to handle errors in HTML5 Web Workers?
- How to handle popup windows in Selenium?
- How to handle chrome notification in Selenium?
- How to handle proxy in Selenium in Java?
- How to handle frames in Selenium with python?
- How to handle frames in Selenium Webdriver in Python?
- How to handle frame in Selenium WebDriver using java?
- How to handle child windows in Selenium with python?
- How to get userAgent information in Selenium Web driver?
- How to use Selenium WebDriver for Web Automation?

Advertisements