I was also facing the same problem and I spent more than a week to fix it. Restarting my machine seemed to have fixed it, but only temporarily.
There was a solution to increase the maximum number of ephemeral ports by editing the registry file. That seemed to have fixed the problem but that also, only temporarily.
For sometime, I kept thinking if I was trying to access a driver which is no longer available, so I have tried to call:
driver.quit()
And then recreate the browser instance, which only gave me: SessionNotFoundException.
I now realized that I had used BOTH System.setProperty
as well as ffCapability.setCapability
to set the path of the binary.
I then tried with only System.setProperty
=> No luck there.
Only ffCapability.setCapability
=> Voila!!! So far it has been working fine. Hopefully it will work great when I try to re-run my scripts tomorrow and the day after and the day after... :)
Bottomline: Use only this
ffCapability.setCapability("binary", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); //for windows`
Hope it helps!