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 are the different types of web controller APIs supported in Selenium?
What is an absolute xpath?
What is desired capability? How is it useful in terms of selenium?
How to handle alerts in selenium webdriver?
Other than the default port 4444 how you can run selenium server?
How to send alt/shift/control key in selenium webdriver?
what is your approach clicking all the links which are available on the page?
Why and how will you use an excel sheet in your project?
How selenium grid works?
What is the difference between MaxSessions vs. Selenium grid MaxInstances properties?
Give the example for method overload in webdriver.
Can we edit recorded selenium ide test cases?
List out the technical challenges with selenium?
What are the main advantages of selenium grid?
What is heightened privileges browsers?