Selenium WebDriver Error: invalid session id

I found what went wrong.

We are using a library to cache api response during test after they are made for the first time.

The problem is, the driver sends a request to get a session id. This is why the first time the tests were passing. The library cached the response from the driver which had the same session id everytime, hence the error from chrome.

If you're using such libraries (VCR, ephemeral_response) and get similar error this is something you might want to investigate


The first thing I notice is that you're using a 3 year old version of Capybara with new versions of selenium-webdriver, Chrome, and chromedriver. Since selenium-webdriver doesn't follow SemVer expecting those to work correctly together is a stretch. You probably want to upgrade Capybara.

Often this error is caused by resource issues with Chrome. Since you appear to be running on MacOS that's not as likely as if you were running this in containers. However it wouldn't hurt to try adding the disable-dev-shm-usage chrome option, and/or setting the window size smaller to see if the error goes away. You could also just try a reboot.

Beyond that a couple of other potentials are

  1. You have an after block registered that has already closed the session - comment out the after block and see if the issue goes away

  2. A bug in chromedriver 74 (of which a few have been reported - https://bugs.chromium.org/p/chromedriver/issues/detail?id=2885, etc) - try rolling back to chrome and chromedriver 73 to see if the issue goes away