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 selenese and what are the types of selenese?
What are the capabilities of selenium webdriver or google webdriver or selenium 2.0?
How can you use the recovery scenario in selenium webdriver?
How to get a text of a web element?
How to execute javascript in selenium?
Tell me what kind of mouse actions can be performed in selenium?
What is object repository? How can we create an object repository in selenium?
When we use findElement () and findElements () findElement ()?
What is the firefoxdriver, class or an interface? And which interface does it implement?
How can we find all the links on a web page?
Tell us what kinds of test types are supported by selenium?
When do we use findelement() and findelements()?
What are the different types of drivers available in webdriver?
How can we capture screenshots in selenium?
How to login into any site if it is showing an authentication pop-up for username and password?