Changes done to fix issue 7134 to avoid race conditions.

Changes done to fix issue 7134 to avoid race conditions.

https://code.google.com/p/selenium/issues/detail?id=7134

I had already signed the CLA.