Handling JavaScript alerts when leaving a page with WebDriver