/*
* Pop-up handling in Selenium WebDriver
* Programming language : JAVA
*
* Here we will browse Rediff site and close the pop-up .
* We will print the pop-up window URL and the main window URL
*/
import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class PopUpHandling {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
// for chrome browser setting
//System.setProperty("webdriver.chrome.driver", "D:/setup/chromedriver.exe");
//WebDriver driver = new ChromeDriver();
driver.get("http://www.rediff.com/");
// Since the Window Handles are unique , we will use java.util.Set to store as it does allow the duplicate values.
// Windows Handles is of type String, so we store the value of window handle as String in Set
Set<String> winHandle = driver.getWindowHandles();
// just to check the number of total windows , in this case its 2
System.out.println("Total number of Windows : "+ winHandle.size());
// Iterator is use to iterator through Set , we can use for loop also
Iterator<String> it = winHandle.iterator();
String parentWindow = it.next();
String childWindow = it.next();
// switch to child window / pop-up window
driver.switchTo().window(childWindow);
System.out.println("child URL/ Title : " + driver.getCurrentUrl() );
driver.close(); // close the child /popUp window
driver.switchTo().window(parentWindow);
System.out.println("parent URL/ Title : " + driver.getCurrentUrl() );
}
}
A blog about new technology, Android, iOS, Mobile Automation, Appium, Web Automation, Selenium, JAVA, Shell Scipting, Powershell, Testing Tools, QA, Spring Boot, Free Software, How to design best frameworks etc..
Selenium WebDriver : How to handle PopUp and close it
Subscribe to:
Post Comments (Atom)
πAnnouncement : Visit the new website/blog π
πππ Announcement : Visit the new website/blog πππ Dear readers, Thank you for reading my blog. If you could have used the little info...
-
How to find the UDID of Android Device What is UDID : It stands for Unique Device Identifier. UDID is required duri...
-
How to change language of device using commandLine Changing language in Android device on-the fly is needed when we are running or exe...
-
To setup Appium for mobile automation, you will need below items to be configured in your test environment. 1. Appium server : 1.1 D...
-
How to get the package name of Android application There are multiple ways in which we can obtain the package name of Android .apk file. ...
No comments:
Post a Comment