Q:

Selenium catch popup on close browser

I'm trying to test that when I close my window a popup shows with a warning message.
I've tried both driver.close() and driver.quit() after making sure I'm on the proper window but this just terminates the process since my popup doesn't show.
I could test it by using the awt Robot and sending alt+f4 but this doesn't seem too reliable.
What would be the proper way to do this?

A:

Instead of using driver.quit() to close the browser, closing it using the Actions object may work for you. This is another way to close the browser using the keyboard shortcuts.
Actions act = new Actions(driver);
act.sendKeys(Keys.chord(Keys.CONTROL+"w")).perform();

Or, if there are multiple tabs opened in driver window:
act.sendKeys(Keys.chord(Keys.CONTROL,Keys.SHIFT+"w")).perform();

