This blog is for Automation Test Engineers

Friday, 16 February 2018

How to close specified browser in Child browser popup in selenium webdriver


//open browser
WebDriver driver=new FirefoxDriver();


//navigate to website



//windowhandle of parent browser

String a=driver.getWindowhandle();
System.out.print(a);


//click on login button

driver.findElement(By.id(“loginsubmit”)).click();


//Size of windowhandles  child browser

Set<String> b=driver.getWindowhandles();
System.out.print(b.size());


// windowhandles of  child browser

Iterator<String>c=driver.getWindowHandles().iterator();

While(c.next()){

String d=c.hasnext();

driver.switchTo().Window(d);

String aTiltle= driver.getTitle();

System.out.print(aTiltle);

if (aTitle.equals("NetBanking"){

driver.close();

}

0

0 comments:

Post a Comment