I have a test case with following scenario:
1) Navigate to website.
2) Enter Login Credential.
3) Click on Login.
After login in my application, login window is closed by system and new child window is the homepage. I am unable to interact with the elements of the new child window.
public class testRegister {
public static void main(String[] args) throws InterruptedException {
int i = 0;
ArrayList<String> ar = new ArrayList<String>();
System.setProperty("webdriver.ie.driver","E:/Jigar Old Back up/Selenium/IEDriverServer.exe");
System.setProperty("webdriver.ie.driver.loglevel", "TRACE");
System.setProperty("webdriver.ie.driver.logfile", "E:/selenium.log");
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
WebDriver driver = new InternetExplorerDriver(ieCapabilities);//
driver.navigate().to("http://172.16.4.90:20125/BPS/");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
String loginwindow = driver.getWindowHandle();
System.out.println(loginwindow);
driver.findElement(By.xpath("/html/body/form/table[2]/tbody/tr/td[2]/table/tbody/tr[2]/td/table/tbody/tr[1]/td[3]/input")).clear();
driver.findElement(By.xpath("/html/body/form/table[2]/tbody/tr/td[2]/table/tbody/tr[2]/td/table/tbody/tr[1]/td[3]/input")).sendKeys("WCHMOD_MAKER1");
driver.findElement(By.xpath("//img[@src='images/indeximages/Login_button.gif']")).click();
for (String winHandle : driver.getWindowHandles()) {
ar.add(winHandle);
System.out.println(winHandle);
}
driver.switchTo().window(ar.get(ar.size()-1));
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element1 = wait.until(ExpectedConditions
.visibilityOfElementLocated(By.xpath("//img[@src='images/wf/Logo2.jpg']")));
driver.findElement(By.xpath("//div[@class=M5]")).click();
Exception faced : Unable to locate element on closed window