changes from https://code.google.com/p/selenium/source/detail?r=8c3c65772d57