How to close the pop up window in selenium running?

萝らか妹 提交于 2020-01-01 08:56:09

问题


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.



来源:https://stackoverflow.com/questions/4720180/how-to-close-the-pop-up-window-in-selenium-running

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!