Reputation: 21
I am new to selenium web driver I am trying to Login to a webpage which leads to auto close the Login page then open the browser in another window, here when i try to click the Logout button in the new page it is saying the error as "Unable to find element on closed window".
Please some one suggest me in how to handle this situation
Regards, Pavan
Upvotes: 2
Views: 9314
Reputation: 141
Not sure if this the correct solution, but when I tried to run the test case using non - admin instance of Visual Studio 2013 I was getting the Unable to find element on closed window exception. But when I ran the same case as administrator the test case worked as expected and this exception was not thrown.
Upvotes: 1
Reputation: 392
What happens when you try something like this?
driver.switchTo().defaultContent();
Upvotes: 1
Reputation: 9029
You'll need to switch windows. This link has a good rundown on how you can do this:
How to switch to the new browser window, which opens after click on the button?
The relevant part for you is this:
//Store the current window handle
String winHandleBefore = driver.getWindowHandle();
//Perform the click operation that opens new window
//Switch to new window opened
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
// Perform the actions on new window
Upvotes: 2