Create a gist now

Instantly share code, notes, and snippets.

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() {
bLogger.info("Inside dismissFirefoxCrashAlert");
HWND hwnd = User32.INSTANCE.FindWindow (null, "Firefox"); // window title
if (hwnd == null) {
bLogger.info("Firefoxdialog is not showing");
}
else {
bLogger.info("Firefoxdialog IS showing. Closing it now.");
User32.INSTANCE.PostMessage(hwnd, WinUser.WM_CLOSE, null, null);
}
}
Owner

nmschorr commented Sep 20, 2015

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