2

ElementExist exception

I have recently updated Chrome and its web driver from version 103 to version 106. The piece of code, contained in the attached image, which previously worked now goes into exception with the following error message:

"OpenQA.Selenium.WebDriverException: invalid argument: uniqueContextId not found (Session info: chrome=106.0.5249.62)"

I have found that the point where the exception is thrown is as follows ExpectedConditions.ElementExists(loadingLocator)

Does anyone have a suggestion or has already run into the problem described?

Thanks

1
  • You should add the HTML source for the element you are getting error. Also, is your chrome binary up-to-date according to your browser version.
    – Akzy
    Commented Feb 1, 2023 at 4:54

3 Answers 3

5
+200

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.

0

When it comes to suggestions, not a 100% certain answer, I would check if the locator is always unique. The error message states "uniqueContextId not found", so the uniqueness of the locator match may be important.

You could try something like this:

IList<IWebElement> elements = driver.FindElements(loadingLocator);

and investigate the number of elements. However, this is just a guess.

Additionally, I would double-check the version of the ChromeDriver, but I assume you've already done so before posting your question.

0
0

In my case changing the web driver manager to version 5.4.1 helped. Chrome browser version 118.0.5993.88.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.