If you were switching between frames or windows and after this searched for element instantly, this may cause the issue. If the frame had been closed, and even if you switched to default context, element search could've still gone to old context, which was no longer there, it's not completely impossible.
I would try to make it slower. Check that frame exists before switching to it. Switch back and check that you really switched to default context. Check that there is no other frame. Avoid checking for elements potentially in that frame.
Quick search over github for chrome-related projects gives this:
https://github.com/v8/v8/blob/9c012f1143703d0353e7a8092d1723aef870cfc3/src/inspector/v8-runtime-agent-impl.cc#L212 which is a possible indication (given the repository nature) that you website contains some tricky javascript (for opening frames, e.g.) and chrome/chromedriver/selenium alltogether get surprised while it's being executed.
UPD
It seems that prior to Chrome/chromedriver 104 (or 105) it was allowed to check for element of default context without yet switching to it, while the current frame no longer existed (removed from DOM). This is not correct behaviour, but it was allowed until some point, the exception was suppressed internally.
When you make a shock upgrade to e.g. version 109, this exception is reliably reproduced, given that experimental options are enabled. uniqueContextId
seems to be a part of mechanism responsible for validation of am I in the right place to do this action
, in this case, frame (context). Unfortunately, chrome command line doesn't seem to have options to toggle this behaviour and uniqueContextId
is mutually exclusive with contextId
as per selenium source (link may cease to exist, just insert active version instead of v110)
You should always switch back to a frame, even if it's a default content, before doing checks on it. There is no inheritance.
HTML
source for the element you are getting error. Also, is yourchrome binary
up-to-date according to your browser version.