I want my script to switch windows. It should switch to second window and again switch back to the first one so that i can continue operations in the current window. I cannot find why the first window is already closed.
public void doDetails(){
logger.info("########## Started ##########");
// Store the current window handle
String winHandleBefore = driver.getWindowHandle();
getAllComponents();
mouseOnArrow();
WaitUtils.waitUntilVisiblityOfElement(driver,link,WaitUtils.FIVE_SECONDS);
//Click operation opens another window/tab
link.click();
WaitUtils.waitForSeconds(WaitUtils.FIVE_SECONDS);
//Switching to new window
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
addFilter();
WaitUtils.waitForSeconds(WaitUtils.TEN_SECONDS);
components.clickCustomize();
WaitUtils.waitUntilVisiblityOfElement(driver,components.allCheckboxes,WaitUtils.TWENTY_SECONDS);
components.clickAllChkBoxes();
WaitUtils.waitForSeconds(WaitUtils.ONE_SECOND);
clickAllDetail();
WaitUtils.waitForSeconds(WaitUtils.ONE_SECOND);
components.clickApply();
WaitUtils.waitUntilInvisibilityOf(driver,components.customizeHeader,WaitUtils.TWENTY_SECONDS);
sortByAllowedAmount();
WaitUtils.waitUntilInvisibilityOf(driver,components.loading,WaitUtils.TWENTY_SECONDS);
clickExcel();
WaitUtils.waitForSeconds(WaitUtils.TEN_SECONDS);
//Closing current window
driver.close();
//Switching back to first window
driver.switchTo().window(winHandleBefore);
}