package com.seleniumWebdriver;
import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
/**
* @Blog Name : Selenium Code Example
* @author Deepak Gupta
* @Created Date 4-08-2017
*
*/
public class BrowserMultiplePopups {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("https://irctc.co.in/");
// click on hotels to get the second browser (child)
driver.findElement(By.linkText("Hotels")).click();
Thread.sleep(7000);
Set<String> windowHandles = driver.getWindowHandles();
Iterator<String> it = windowHandles.iterator();
String parent = it.next();
String child = it.next();
// switch to child
driver.switchTo().window(child);
// click on link to open the third browser
driver.findElement(By.xpath("//a[@href='http://www.railtourismindia.com/cgi-bin/dev1.dll/irctc/enquiry/bannerdetails.jsp?code=GIN01']")).click();
Set<String> allWindowHandles = driver.getWindowHandles();
Iterator<String> it1 = allWindowHandles.iterator();
String parent1 = it1.next();
String child1 = it1.next();
String gc = it1.next();
driver.switchTo().window(gc);
driver.findElement(By.id("air_fromdate")).click();
driver.close();
driver.switchTo().window(child1);
driver.close();
driver.switchTo().window(parent1);
driver.close();
}
}
import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
/**
* @Blog Name : Selenium Code Example
* @author Deepak Gupta
* @Created Date 4-08-2017
*
*/
public class BrowserMultiplePopups {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("https://irctc.co.in/");
// click on hotels to get the second browser (child)
driver.findElement(By.linkText("Hotels")).click();
Thread.sleep(7000);
Set<String> windowHandles = driver.getWindowHandles();
Iterator<String> it = windowHandles.iterator();
String parent = it.next();
String child = it.next();
// switch to child
driver.switchTo().window(child);
// click on link to open the third browser
driver.findElement(By.xpath("//a[@href='http://www.railtourismindia.com/cgi-bin/dev1.dll/irctc/enquiry/bannerdetails.jsp?code=GIN01']")).click();
Set<String> allWindowHandles = driver.getWindowHandles();
Iterator<String> it1 = allWindowHandles.iterator();
String parent1 = it1.next();
String child1 = it1.next();
String gc = it1.next();
driver.switchTo().window(gc);
driver.findElement(By.id("air_fromdate")).click();
driver.close();
driver.switchTo().window(child1);
driver.close();
driver.switchTo().window(parent1);
driver.close();
}
}
No comments:
Post a Comment