How do you handle Multiple windows in your application?

Answer Posted / jameel shaik

static WebDriver driver;
@Test
public void Window_Handle() throws InterruptedException
{
System.setProperty("webdriver.chrome.driver","F:\drivers\chromedriver_win32(1)\chromedriver.exe");
driver=new ChromeDriver();
driver.get("https://accounts.google.com");
Thread.sleep(3000);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id='view_container']/form/div[2]/div/div[2]/div[2]")).click();
Actions a=new Actions(driver);
a.sendKeys(Keys.ENTER).perform();
//driver.findElement(By.xpath("//*[@id='SIGNUP']/div")).click();
Thread.sleep(3000);
driver.findElement(By.linkText("Learn more")).click();
String ParentWindow=driver.getWindowHandle();
System.out.println("Before Opening The Site"+driver.getTitle());
Set<String> ChildWindow=driver.getWindowHandles();
System.out.println("Before Opening The Site"+ driver.getTitle());


Iterator<String> it=ChildWindow.iterator();

while(it.hasNext())
{
String Child=it.next();
System.out.println("Getting Child Window Title After Opening"+ driver.getTitle());
if(!ParentWindow.equalsIgnoreCase(Child))
{
driver.switchTo().window(Child);
driver.findElement(By.xpath("/html/body/div[2]/header/div[4]/div/div/div/span/a/span")).click();
driver.close();
}
}
driver.switchTo().window(ParentWindow);
System.out.println("After Opening The Site" +driver.getTitle());



}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the different types of web controller APIs supported in Selenium?

565


What is an absolute xpath?

567


What is desired capability? How is it useful in terms of selenium?

455


How to handle alerts in selenium webdriver?

493


Other than the default port 4444 how you can run selenium server?

466






How to send alt/shift/control key in selenium webdriver?

1053


what is your approach clicking all the links which are available on the page?

492


Why and how will you use an excel sheet in your project?

2968


How selenium grid works?

478


What is the difference between MaxSessions vs. Selenium grid MaxInstances properties?

587


Give the example for method overload in webdriver.

542


Can we edit recorded selenium ide test cases?

493


List out the technical challenges with selenium?

499


What are the main advantages of selenium grid?

493


What is heightened privileges browsers?

561