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
List out different types of locators?
Explain how you can handle frames using selenium 2.0?
How you can find broken images in a page using selenium web driver?
What are the advantages of rc?
What is the alternate way to click on the login button?
Explain dataproviders in testng using an example. Can I call a single data provider method for multiple functions and classes?
Explain what are the different types of locators in selenium?
List the different types of drivers in webdriver.
What are different types of locators?
What is page object model in selenium?
When should I use selenium grid?
What selenese command and argument can be used to transfer the value of a javascript variable into a side variable?
Can captcha be automated?
What are the advantages of selenium as a test tool?
how to handle staleelementreferenceexception?