FirefoxDriver
doesn't switch back to main window after opening new tab.. This works perfectly fine on ChromeDriver
..
I've a main webpage with multiple <a>
elements/links and I want to open each link in a new tab and then switch back to main page.
FirefoxDriver
is not treating the new tab as a windowHandle.. when I try to print the size of window handles it is returning just one in FirefoxDriver
whereas it's returning two in ChromeDriver
which is fine..
driver.get(url);
WebElement webelement= driver.findElement(By.xpath("html/body/div[1]"));
List<WebElement> allLinks = webelement.findElements(By.tagName("a"));
int totalSize = listofSites.size();
int splitedvalue = totalSize / Integer.parseInt(split2);
int startValue = splitedvalue * (Integer.parseInt(split1) - 1);
for( int i= startValue ; i<endValue; i++ ){
links_URL.add(allLinks.get(i).getAttribute("href"));
String url = allLinks.get(i).getAttribute("href");
String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN);
allLinks.get(i).sendKeys(selectLinkOpeninNewTab);
tabs2 = new ArrayList<String> (driver.getWindowHandles());
driver.switchTo().window(winHandleBefore);
}
for( int k= 1 ; k< tabs2.size(); k++ ){
System.out.println("size of tab2 "+tabs2.size());
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(tabs2.get(k));
}
routeToproperloginpage(emailID, password, url_array.get(k-1) );
driver.switchTo().window(winHandleBefore);
}
}