Posts Tagged ‘Selenium’

Java JNA to Dismiss Windows 7 Dialog

Friday, October 2nd, 2015

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:

Selenium with Java Testing a Website

Friday, October 2nd, 2015

This video shows the Eclipse IDE running a web test written with Selenium, Java, JUnit, Log4j2, Maven and other packages. It tests against my own website: which is also known as

The tests are run with JUnit, so each test stands on its own and can be run independently of the others. Each test launches a fresh instance of FireFox with Selenium WebDriver. The tests use Maven and a Maven pom.xml file to specify dependencies. The entire suite was written in and runs with Eclipse on a Windows 7 PC.

The source code can be viewed on GitHub at:

This demo was done with inverted color on a Windows 7 machine. I’m using inverted color a lot lately because it’s easier on the eyes.

The script also includes full Maven Surefire site test result reporting which I hope to share in a future video. To read more about Selenium, see:

Thank you for helping me learn Selenium. Their Selenium Course was very useful and free.