I'm getting the following exception when calling GetShadowRoot() method in Selenium using C#:
{"javascript error: circular reference\n (Session info: chrome=114.0.5735.199)"} OpenQA.Selenium.JavaScriptException
Error stack:
at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute)
at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary2 parameters)
at OpenQA.Selenium.WebDriver.InternalExecute(String driverCommandToExecute, Dictionary2 parameters)
at OpenQA.Selenium.WebElement.Execute(String commandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.WebElement.GetShadowRoot() at TestProject1.UnitTest1.Test1() in C:\Git\TestProject1\UnitTest1.cs:line 27
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
Code:
driver.Navigate().GoToUrl("https://mypage.address");
driver.FindElementCustom(By.XPath("//control-element"));
driver.SwitchTo().Frame("content");
var host = driver.FindElementCustom(By.CssSelector("shadow.root element"));
var root = host.GetShadowRoot();//error here
var menu = root.FindElement(By.CssSelector("div.menu-container button"));
I'm using Selenium 4.10 with C# bindings, the latest Chrome, and the matching ChromeDriver version.
I tried so far:
- using GetShadowRoot() method
- using JSExecutor
In both cases, I'm getting the mentioned error.
All selectors are CSS Selectors, they work fine in Chrome DevTools.
Shadow DOM is found correctly and the target element is also found when doing "querySelector().shadowRoot.querySelector()".
Shadow DOM is in "Open" mode.
I created a separate minimal test to rule out any influence of the test framework, but no success.