Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing onbeforeunload events from Selenium

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.

like image 795
Moss Collum Avatar asked Oct 02 '08 19:10

Moss Collum


2 Answers

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.

like image 138
Thom Avatar answered Sep 21 '22 07:09

Thom


faced same problem with "beforeunlaod" event listner, LUMINUS! a chrome addon that helps me just block the event listener in the plugin thats all..

like image 28
J07H15H Avatar answered Sep 24 '22 07:09

J07H15H