Skip to main content

Handling Modal Dialog Window in Selenium Webdriver

Handling Modal Dialog Window in Selenium Webdriver



In this tutorial we are going to see how to handle "Modal Dialog Window"  using Selenium Webdriver

Disadvantage using Selenium

  • Use Can't handle elements which is inside Modal Dialog Window.

Using Robot Class
  • Using Robot Class we can handle Modal Dialog Window.

In this tutorial

  • Open http://vodkabears.github.io/remodal/#
  • Click on Show button
  • In the Modal Dialog Window. Click on Follow button 


Source Code :


import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Toolkit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;


public class robot_demo {

public static void main(String[] args) throws InterruptedException, AWTException {
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://vodkabears.github.io/remodal/#");
Thread.sleep(5000);
driver.findElement(By.linkText("Show")).click();
Thread.sleep(7000);
Robot rb=new Robot();
rb.keyPress(KeyEvent.VK_TAB);  
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_TAB);  
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_TAB);  
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_TAB);  
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_TAB);  
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_ENTER);

}
}

Hope you like this post

Thankyou.

Comments

Popular posts from this blog

ExtentReports in Selenium Webdriver

ExtentReports in Selenium Webdriver What is ExtentReport? ExtentReports  is a HTML reporting library for Selenium WebDriver for Java which is extremely easy to use and creates beautiful execution reports. It shows test and step summary, test steps and status in a toggle view for quick analysis Download Download the jar below: Download ExtentReports 1.4 (1623)    Snapshot of Extent report After Executing the Script   Program Steps:  We are going to write three different testcases. Pass Warning Fail TestCase with Pass Result Navigate to http://www.guvi.in Click on Sign-in Enter the credientials Check the URL is correct or not after login   TestCase with Warning Result Verify with the Wrong URL (static String Afterloginfail="http://www.guvi.in/ ")    TestCase with fail Result Click on Menu Select Tech Challenges Verify With wrong URL. Source Code: import  java.io.File; import  j...

Autonium

About Autonium Autonium is a test automation framework for web applications. This framework is built by using Java and Selenium. It uses Maven project structure. Easy to understand and use it. Having basic idea on Java, Selenium, Maven and TestNG is good enough to start with Autonium. Let’s start Automation with Autonium --------------------------------------------------- Advantages Provides support to all major browsers –  Firefox, Chrome, IE and Safari . Capability of executing scripts on  Remote Machines  by using Selenium Server. Users can make use of Selenium Web driver methods and Autonium methods. Autonium simplifies  Test data management . Test data can be read from properties files. Scripts can be developed without  hard coding  test data . Identifiers can also be read from properties files and  hard coding   of identifiers can be avoided. Test data and Identifier v...