Skip to content

Instantly share code, notes, and snippets.

Last active September 26, 2015 04:05
What would you like to do?
Dismiss FireFox crash alert brought on by Selenium.using JNA.
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinUser;
protected static void dismissFirefoxCrashAlert() {"Inside dismissFirefoxCrashAlert");
HWND hwnd = User32.INSTANCE.FindWindow (null, "Firefox"); // window title
if (hwnd == null) {"Firefoxdialog is not showing");
else {"Firefoxdialog IS showing. Closing it now.");
User32.INSTANCE.PostMessage(hwnd, WinUser.WM_CLOSE, null, null);
Copy link

This snippet shows how to dismiss an alert triggered by FireFox that is actually put up by Windows during a Selenium test. Since Selenium can't dismiss the alert itself, we use the JNA library to dismiss the alert window instead. This alert problem is described in at least two Firefox bug reports: 1157672 and 1167511, and in Selenenium Bug #437 .

Known bug reports associated with this problem:
Bug 1167511 - Firefox - When running selenium automated test, a window pops up saying "Firefox has stopped working"
Bug 1157672 - Firefox crashes on shutdown when invoked with -silent and empty profile directory
Selenenium Bug #437- Firefox 38 doesn't work with WebDriver 2.45.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment