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
Can you use Selenium to test the Rest API or Web services?
Why testers should opt for selenium and not qtp?
Give selenium ide tool disadvantage?
what are challenges you faced in your last project?
Name an api used for reading and writing data to excel files?
Why to use testng with selenium rc?
What are the drawbacks of selenium ide
What are its advantages of pom?
Tell me how you can capture server side log selenium server?
How will you use selenium to upload a file?
Explain what is the difference between borland silk and selenium?
What is the use of javascriptexecutor?
What is the difference b/w close () and quit ()?
How you can insert a start point in selenium ide?
What exactly is selenium remote-control (rc) tool?