How to click on OK button on Confirm box?

nincequamic

New Member
I'm testing an ASP.NET web form application. For IE, when I close the browser, a \[code\]Confirm\[/code\] box pops up and I need to click on the \[code\]OK\[/code\] button with Selenium Web Driver.The JavaScript that pops up the box is:\[code\]<script type="text/javascript"> //<![CDATA[ function onBeforeUnloadAction() {return 'Are you sure to leave ALNW? All unsaved data will be discarded.';} window.onbeforeunload = function () {if ((window.event.clientX < 0) || (window.event.clientY < 0)) {return onBeforeUnloadAction();}} //]]></script>\[/code\]The code to handle the \[code\]Confirm\[/code\] box is:\[code\]driver.Close();var alert = driver.SwitchTo().Alert();alert.Accept();\[/code\]The problem is the \[code\]Confirm\[/code\] box just sitting there and the test fails. I do get the following exception at \[code\]driver.Close()\[/code\]:\[code\]Modal dialog present (UnexpectedAlertOpen)\[/code\]
 
Back
Top