How do you handle Multiple windows in your application?

Answers were Sorted based on User's Feedback



How do you handle Multiple windows in your application?..

Answer / deepa

driver.findElement(By.id(“id of the link which opens new window”)).click();

//wait till two windows are not opened

waitForNumberofWindowsToEqual(2);//this method is for wait

Set handles = driver.getWindowHandles();

firstWinHandle = driver.getWindowHandle(); handles.remove(firstWinHandle);

String winHandle=handles.iterator().next();

if (winHandle!=firstWinHandle){

//To retrieve the handle of second window, extracting the handle which does not match to first window handle

secondWinHandle=winHandle; //Storing handle of second window handle

//Switch control to new window

driver.switchTo().window(secondWinHandle);

Is This Answer Correct ?    4 Yes 0 No

How do you handle Multiple windows in your application?..

Answer / suresh777

Set<String> parent=driver.getWindowHandles();

Object[] child=parent.toArray();

driver.switchTo().window((String) child[1]);

Here we have handle at any number of Windows

Is This Answer Correct ?    4 Yes 0 No

How do you handle Multiple windows in your application?..

Answer / chetan phani.j

We handle Multiple popups by using getwindowhandles().

Is This Answer Correct ?    1 Yes 0 No

How do you handle Multiple windows in your application?..

Answer / 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

More Selenium Interview Questions

How to create and run testng.xml?

0 Answers  


What is the purpose of the getoptions() method?

0 Answers  


What are various ways of locating an element in selenium?

0 Answers  


How are web-based pop-ups handled in selenium?

0 Answers  


What is the selenese command to show the value of a variable in the log file?

0 Answers  






How do you verify an object presented in multiple pages?

0 Answers  


What is webdriverbackedselenium?

0 Answers  


How to find whether an element is displayed on the web page?

0 Answers  


What is the difference between selenium and qtp?

0 Answers  


Tell me how you can capture server side log selenium server?

0 Answers  


What could be the cause of the selenium webdriver test to fail?

0 Answers  


How will you find an element using selenium?

0 Answers  


Categories