Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close the pop up window in selenium running?

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?

like image 204
susantjs Avatar asked Jan 18 '11 03:01

susantjs


1 Answers

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);
like image 142
stefan Avatar answered Oct 19 '22 06:10

stefan