0
votes

MY Test case is like on click of one Button(Update Customer) a new Window will open,after opening user verifies Data and will CLose the Window. The control need to back to Previous Window

I Have Written driver.close() . but it's not working

1

1 Answers

1
votes

I think you problem is that the WebDriver is not focusing on the previous window.

Save your previous window handle:

String myWindowHandle = driver.getWindowHandle();

You can do this after you close the window:

driver.SwitchTo().window(myWindowHandle);

Update

String myWindowHandle = driver.getWindowHandle();

// click operation that opens new window

// Switch to new window opened
for(String winHandle : driver.getWindowHandles()){
    driver.switchTo().window(winHandle);
}

// Do stuff

driver.close(); // This will close the current window (new one)

// Switch back to first window
driver.switchTo().window(myWindowHandle);