import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class HDFC_tab2 {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "c:\\meeraja\\chromedriver.exe");
WebDriver driver= new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://www.hdfc.com");
Set<String> winids= driver.getWindowHandles(); //set of strings
System.out.println(winids.size());
Iterator<String> iter= winids.iterator();
System.out.println(iter.next());
System.out.println("**************************");
//main
driver.findElement(By.xpath("//*[@id='acc-1-head-2']/a")).click();
driver.findElement(By.xpath("//*[@id='acc-1-section-2']/li[2]/a")).click();
System.out.println("**************************");
System.out.println("**************************");
winids= driver.getWindowHandles(); //set of strings
System.out.println(winids.size());
iter= winids.iterator();
String mainwinid= iter.next();
String tabwinid= iter.next();
System.out.println(mainwinid);
System.out.println(tabwinid);
driver.switchTo().window(tabwinid);
//driver.findElement(By.xpath("//*[@id='ic-news']")).click();
driver.findElement(By.xpath("html/body/table/tbody/tr[2]/td/table/tbody/tr/td[3]/table/tbody/tr/td/table/tbody/tr[1]/td/table/tbody/tr[2]/td/p[2]/a")).click();
System.out.println("**************************");
System.out.println("**************************");
System.out.println("**************************");
winids= driver.getWindowHandles();
System.out.println(winids.size());
iter= winids.iterator();
mainwinid= iter.next();
tabwinid= iter.next();
String tabwinid2= iter.next();
System.out.println(mainwinid);
System.out.println(tabwinid);
System.out.println(tabwinid2);
driver.switchTo().window(tabwinid2);
driver.findElement(By.xpath("//*[@id='popup']/table/tbody/tr/td/table[2]/tbody/tr/td/table[1]/tbody/tr[4]/td/p/font/b/a")).click();
driver.close();//close will only close the tab
//driver.exit will close all the tabs and window
driver.switchTo().window(mainwinid);
}
}
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class HDFC_tab2 {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "c:\\meeraja\\chromedriver.exe");
WebDriver driver= new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://www.hdfc.com");
Set<String> winids= driver.getWindowHandles(); //set of strings
System.out.println(winids.size());
Iterator<String> iter= winids.iterator();
System.out.println(iter.next());
System.out.println("**************************");
//main
driver.findElement(By.xpath("//*[@id='acc-1-head-2']/a")).click();
driver.findElement(By.xpath("//*[@id='acc-1-section-2']/li[2]/a")).click();
System.out.println("**************************");
System.out.println("**************************");
winids= driver.getWindowHandles(); //set of strings
System.out.println(winids.size());
iter= winids.iterator();
String mainwinid= iter.next();
String tabwinid= iter.next();
System.out.println(mainwinid);
System.out.println(tabwinid);
driver.switchTo().window(tabwinid);
//driver.findElement(By.xpath("//*[@id='ic-news']")).click();
driver.findElement(By.xpath("html/body/table/tbody/tr[2]/td/table/tbody/tr/td[3]/table/tbody/tr/td/table/tbody/tr[1]/td/table/tbody/tr[2]/td/p[2]/a")).click();
System.out.println("**************************");
System.out.println("**************************");
System.out.println("**************************");
winids= driver.getWindowHandles();
System.out.println(winids.size());
iter= winids.iterator();
mainwinid= iter.next();
tabwinid= iter.next();
String tabwinid2= iter.next();
System.out.println(mainwinid);
System.out.println(tabwinid);
System.out.println(tabwinid2);
driver.switchTo().window(tabwinid2);
driver.findElement(By.xpath("//*[@id='popup']/table/tbody/tr/td/table[2]/tbody/tr/td/table[1]/tbody/tr[4]/td/p/font/b/a")).click();
driver.close();//close will only close the tab
//driver.exit will close all the tabs and window
driver.switchTo().window(mainwinid);
}
}