A Firefox Extension that automatically closes alerts. Its intention is to aid in running Selenium scripts.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Thanks a million to Olle Jonsson (http://github.com/olleolleolle) for adding in all of the Firefox preference additions.

My blog post on this issue:  http://distributed-frostbite.blogspot.com/2010/02/closing-javascript-alerts-in-selenium.html

This is a simple Firefox extension that I use to close unexpected alert boxes while running Selenium tests.  Prior to this the alerts where out of context and Selenium could not control them.  You can see the Selenium-RC FAQ for more information:

While watching Jason Huggins' presentation on Hacking Selenium ( http://www.infoq.com/presentations/huggins-hacking-selenium ), he demonstrated a way to close the alerts at the browser layer (XUL).  This method was sent to him by Aaron Boodman of Greasemonkey fame.  I (Dan Wanek) have taken the base of Aaron's code and turned it into a simple Firefox extension.  It has worked for me in all of the instances that I have needed it, but if you are having issues you may need to tweak the alertCloser.alertClose method to make it more general use.

There is a preference you can set: extensions.alert_closer.millisbeforeclose which defaults to 1000.


To create the XPI for installation into Firefox simply change to the "FirefoxAlertCloser" directory and zip up the contents.  For example:

    git clone git://github.com/zenchild/FirefoxAlertCloser.git
    cd FirefoxAlertCloser
    zip -r ../alert_closer.xpi . -x ".git/*"

Now just go into Firefox and open the xpi file you created.  I would recommend doing this in a special Firefox profile for Selenium testing.