This video uses Java JNA to dismiss a Windows 7 native dialog that pops up while Firefox is launching during a Selenium test. The same technique can be used to manage any Windows 7 native dialog or window from java in many other situations.
In this case, the alert declares that Firefox has crashed, and waits to be manually dismissed. Until dismissed somehow, it blocks Firefox and the test from continuing.
This workaround addresses these logged bugs:
Firefox Bug 1167511 – When running selenium automated test, a window pops up saying “Firefox has stopped working”
Firefox Bug 1157672 – Firefox crashes on shutdown when invoked with -silent and empty profile directory
Selenium Bug #437 – Firefox 38 doesn’t work with WebDriver 2.45.1
This workaround may work in other situations where something within a Selenium script causes a Windows alert dialog window to appear.
The alert can’t be dismissed normally without manual intervention. Selenium can’t see it because it’s put up by by Windows and is not part of the Firefox..The alert needs to go away before the thread that caused it can continue.
Simple scripts run as a single program thread, each step executing after the previous step is done.
We need to start a second program thread to go around the outside of our normal set of steps to dismiss that dialog.
First create a new thread by creating a class that is an extension of the Thread class. Then we add our alert-dismiss code to the run method of this 2nd thread. When the thread starts, the dismiss code will execute.
JNA stands for Java Native Access. It’s a community developed library that supports many languages and platforms like MacOS and Linux. JNA provides a simple set of methods that access more complex lower-level operating system calls. It makes programming system calls easy.
Here’s the snippet of JNA code that closes the alert window:
Here’s the code to create the 2nd thread:
Here’s the code for starting the 2nd thread
See the entire project at: