I have test case to automate in which it will open the gmail and find a received mail using subject and in the body of the mail i have to submit comment in which it will take to the second tab in same window. And i have click on one button in the newly opened tab.
I have tried using the getWindowHandle() and getWindowHandles(). But it has only one window handler for the entire window. Using that handler i can't access the second tab.
String parentHandle = driver.getWindowHandle();
System.out.println(parentHandle);
driver.findElement(By.xpath("//*[@name='comment']")).sendKeys("Comment and Approved From admin Mail");
driver.findElement(By.xpath("//button[contains(text(),'Submit')]")).click();
driver.switchTo().alert().accept();
ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles());
System.out.println(tabs);
tabs.remove(parentHandle);
driver.switchTo().window(tabs.get(0));