Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

handling "are you sure you want to navigate away from this page" Msg in Selenium 2.0

Using Selenium 2.0 After Submitting a web form, A popup msg comes up with the "are you sure you want to navigate away from this page" message, How do I get selenium to press OK or disable this popup?

I have already tried

    Alert alert = driver.switchTo().alert();
    alert.accept(); 

or

    alert.dismiss();

edit:

quick fix, I just overwrote the popup function using JS

    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("window.onbeforeunload = function() {};"); 

    form.submit();

this will stop will disable this popup, the same can be done for js alerts, comfirm and prompt boxes

like image 498
ajoe Avatar asked Jul 25 '11 18:07

ajoe


1 Answers

See if this answer helps:
http://code.google.com/p/selenium/issues/detail?id=27#c6

Overall, the thread raises a similar concern as yours. You are trying to handle this as an alert, see if you can handle this as a js confirmation dialog.

like image 177
Suchit Parikh Avatar answered Nov 05 '22 15:11

Suchit Parikh