Search code examples
seleniumselenium-webdriverselenoid

Explanation of Selenium "Session timed out or not found"


This "Session timed out or not found" error has been a curse on my existence. Often it has ended-up being symptomatic of something else, but I'm currently using Selenium with Chromium (by way of Selenoid) in eight different places, and it works flawlessly in seven of them and failing consistently, during every single run, in another and for seemingly no reason:

...
  File "/opt/obo/virtualenv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
  File "/opt/obo/virtualenv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/opt/obo/virtualenv/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Session timed out or not found

I have not yet seen it have anything actually to do with timeouts, but I still doubled or tripled every timeout I could find, and it was still happening. I reduced the amount of data from returned from the Javascript to Python, and it's still happening. I then timed how long it takes for this to occur, when it occurs, and it looks like (0) seconds. There seems to be no documentation of this error out there and very few references in general. So, maybe someone has some advice or can at least describe what causes this, before I have to tear it apart myself?


Solution

  • This issue seemed to occur every time after I ran through another window with infinite scroll. It infrequently occurred at other times at seemingly-random intervals.

    It could be that some sites do something that put the window into a bad state. It could be me not doing something that I'm not aware of that I need to do after doing an infinite scroll.

    Either way, I added a contingency to detect that specific exception and message and to just close that window and then open a new one on the next cycle. That completely eliminated this error/symptom and ostensibly prevented it from ever coming back.