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
What is the purpose of creating a reference variable- ‘driver’ of type
What are some expected conditions that can be used in explicit waits?
What are the types of text patterns available in selenium?
How many exemptions do you know in selenium webdriver?
Mention when to use autoit?
Explain the difference between close and quit command?
How to find the xpath of web table elements.in chrome or internet explorer.or without using fire bug.?
What is regular expressions? How you can use regular expressions in selenium?
How to validate the dropdown value contains specific value or not?
Explain how you can capture server side log selenium server?
What is a hybrid framework?
Which are the operating systems supported by selenium?
Explain how you can login into any site if it’s showing any authentication popup for password and username?
Explain what is group test in testng?
Explain what is the difference between find elements () and find element ()?