How to close the pop up window in selenium running

2020-07-06 04:31发布

问题:

I wanna close the pop up window (known window name), and back to the original window. What shall I do? If I can't get a constant of the close button in window. so is there any general behavior to reach the goal?

回答1:

Have you tried:

selenium.Close();
selenium.SelectWindow("null");


回答2:

Using WebDriver (shown with Java) you could do something like this:

// instantiate your driver
...

// get window handle
String baseWindowHdl = driver.getWindowHandle();

// navigate to pop-up
...

// close pop-up
driver.close();

// switch back to base window
driver.switchTo().window(baseWindowHdl);


回答3:

I dont know if you are still looking for an answer, but i had some troubles with this. After spending more than one hour on searching for a way to do it, dont want to use webdriver. I tried using the garbage collector:

Selenium selenium = new DefaultSelenium(......);
selenium.start();

................

selenium.close(); //to terminate testing window
selenium = null;  //make sure there are no references to the file
System.gc();      //now the garbage collector can kick in

This worked for me.