I'm trying to write a Selenium test for a web page that uses an onbeforeunload event to prompt the user before leaving. Selenium doesn't seem to recognize the confirmation dialog that comes up, or to provide a way to hit OK or Cancel. Is there any way to do this? I'm using the Java Selenium driver, if that's relevant.
A:
Warning : this gives an alternate solution
Watij -- http://watij.com/ -- can help here. Or if you're comfortable with ruby, watir can help -- http://wtr.rubyforge.org/install.html
anjanb
2008-10-02 20:07:50
+1
A:
You could write a user extension (or just some JavaScript in a storeEval etc) that tests that window.onbeforeunload is set, and then replaces it with null before continuing on from the page. Ugly, but ought to get you off the page.
Thom
2008-10-02 21:19:35
I didn't end up doing this (my requirements changed such that I was better off using a regular alert anyway), but this looks like it would do the trick, and is close to how Selenium handles testing for other alerts.
Moss Collum
2008-11-27 03:36:54