Converting selinium code to headless tests with PhantomJS

The word test here is used ambiguously as I use selenium for more than just UI tests, it makes a great tool for browser automation which I use it for this purpose a lot. While writing your browser automation most of the time it’s easier to do it in browser mode by using the firefox or chrome driver so that you can visually inspect the HTML. Once you are done writing the code and finished testing sometimes you would prefer to switch it to headless mode so that it can be run without having a UI, at which point you are likely to tryout PhantomJS driver and your fully tested code starts throwing all sorts of errors like “Element not found” or “Stale Element Exception”. If all this errors go away if you switch back to chrome or firefox driver then the likeliest cause of your troubles is you might need to add delays in most places where you have the browser loading new data compared to the other browser drivers.
To me this seemed a bit counter intuitive at first as I though headless mode should run faster therefore requiring even less time to load UI changes, but I guess it might actually take a little longer since all the browser rendering is being done is software only. Just thought to put this out there as I have run into the issue a few times.

Getting java JDK as a zip instead of exe

Sometimes you may need to have the java JDK available on your system without having to run the installer exe/msi for different reasons. This solution worked for me with JDK8u45, I haven’t tried it with other JDK versions so your mileage might vary.
Thanks to @Marc T for this solution.


create destination folder (c:\jdk8)
download JDK exe from Oracle
7zip -> unzip into destination folder
Open command prompt and enter cmd [cd c:\jdk8]
Enter this command to unpack the contents of the folder [for /r %x in (*.pack) do .\bin\unpack200 -r "%x" "%~dx%~px%~nx.jar"]

Find and Identify Device ID’s

If you help fix people’s computers you will come across devices that windows will not have drivers for or you may be having problems downloading them from the machine manufacturer site, here is a quick way to go about it.

Go to Device Manager right click on unrecognised device there will be an exclamation mark on it click Properties ->Details and select Hardwae ID’s from the property drop down list. VID_ and VEN_ are used to identify vendors and PID_ and DEV_ identify Product ID. The HEX value following Product ID “PID_/DEV_” or Vendor ID “VID_/VEN_” is what you use in your search to identify the device.

Now go to pcidatabase.com enter your product or vendor id to such for your device.

Code 39

I was trying to work on a computer the other day, it would not recognize it’s DVD drive and switching with another dvd drive did not make a difference. The error message provided was
“Windows cannot load the device driver for this hardware. The driver may be corrupted or missing. (Code 39)”

To solve this Code 39 error, follow these instructions:

1) Close all open programs

2) Click on Start, Run, and type REGEDIT and press Enter

3) Click on the plus signs (+) next to the following folders

  • HKEY_LOCAL_MACHINE
  • SYSTEM
  • CurrentControlSet
  • Control
  • Class
  • {4D36E965-E325-11CE-BFC1-08002BE10318}

4) This folder is the DVD/CD-ROM Drive Class Description in the registry. Look for any of the following names in the right hand column.

  • UpperFilters
  • LowerFilters
  • UpperFilters.bak
  • LowerFilters.bak

5) If  any of the above keys shown in step 4 are listed, right-click on them and choose Delete
6) After deleting the keys, close the Registry Editor
7) Reboot your computer
8) Open My Computer and check to see if your CD or DVD drives have returned. You may also want to open Device Manager and verify that the yellow exclamation and error code on the CD or DVD drive is gone.

I got this info at this site and they even tell you other things you can do with drive errors.