views:

633

answers:

3

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
+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
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
A: 

When I was confronted with limited control which I had over browser using Selenium, I turned to MozLab plugin which solved my problem if only for one browser platform.

dpavlin