Skip to content

Instantly share code, notes, and snippets.

@nmschorr
Last active September 26, 2015 04:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nmschorr/c7ae1fd080022f3efe02 to your computer and use it in GitHub Desktop.
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);
}
}
@nmschorr
Copy link
Author

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