- 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 deal with ModalDialog using selenium webdriver?
We can deal with modal dialog boxes with Selenium. A modal is just like a window that enforces the user to access it prior to going back to the actual page. It can be an authentication window as well.
Let us work with the below modal dialog −
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class ModDialog{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver","C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("http://www.uitestpractice.com/Students/Switchto"); // identify element and click WebElement m = driver .findElement(By.xpath("//button[contains(text(), 'Launch modal')]")); // identify modal header and obtain text WebElement m= driver.findElement(By.xpath("//h4[@class='modal−title']")); System.out.println("Modal Dialog text: " + m.getText()); // click on OK WebElement n= driver.findElement(By.xpath("//button[text()='Ok']")); n.click(); driver.quit(); } }
Output
- Related Articles
- How to deal with security certificates using Selenium?
- How to scroll down using Selenium WebDriver with Java?
- How to scroll to element with Selenium WebDriver using C#?
- How to type in textbox using Selenium WebDriver with Java?
- How to get selected option using Selenium WebDriver with Java?
- How to get selected option using Selenium WebDriver with Python?
- How to handle authentication popup with Selenium WebDriver using Java?
- How to Verify Tooltip using Selenium WebDriver?
- How to upload files using Selenium Webdriver?
- How to deal with reusable components in Selenium Java?
- How to scroll a specific DIV using Selenium WebDriver with Java?
- How to take screenshot with Selenium WebDriver?
- How to send cookies with selenium webdriver?
- Switch tabs using Selenium WebDriver with Java.
- How to select checkboxes using selenium java webdriver?

Advertisements