[🐛 Bug]: UnsupportedOperationException: getShadowRoot on Actions.dragAndDrop()
What happened?
Hello team
Not able to migrate from the 3.141.59 to the 4.21.0
Getting UnsupportedOperationException: getShadowRoot even I don't have any shadow elements in DOM and do not have a method that calls it
I'm using the next classes
Wrapper
`public class WebDriverWrapper implements WebDriver, Interactive { private final WebDriver originalWebDriver;
public WebDriverWrapper(WebDriver webDriver) {
this.originalWebDriver = webDriver;
}
@Override
public void get(String url) {
this.originalWebDriver.get(url);
}
@Override
public String getCurrentUrl() {
return this.originalWebDriver.getCurrentUrl();
}
@Override
public String getTitle() {
return this.originalWebDriver.getTitle();
}
@Override
public List<WebElement> findElements(By by) {
return this.originalWebDriver.findElements(by)
.stream().map(e -> new WebElementWrapper(e, this))
.collect(Collectors.toList());
}
@Override
public WebElement findElement(By by) {
return new WebElementWrapper(this.originalWebDriver.findElement(by), this);
}
@Override
public String getPageSource() {
return this.originalWebDriver.getPageSource();
}
@Override
public void close() {
this.originalWebDriver.close();
}
@Override
public void quit() {
this.originalWebDriver.quit();
}
@Override
public Set<String> getWindowHandles() {
return this.originalWebDriver.getWindowHandles();
}
@Override
public String getWindowHandle() {
return this.originalWebDriver.getWindowHandle();
}
@Override
public TargetLocator switchTo() {
return this.originalWebDriver.switchTo();
}
@Override
public Navigation navigate() {
return this.originalWebDriver.navigate();
}
@Override
public Options manage() {
return this.originalWebDriver.manage();
}
@Override
public void perform(Collection<Sequence> actions) {
if (originalWebDriver instanceof Interactive) {
((Interactive) originalWebDriver).perform(actions);
} else {
throw new UnsupportedOperationException("Wrapped WebDriver does not support perform actions");
}
}
@Override
public void resetInputState() {
if (originalWebDriver instanceof Interactive) {
((Interactive) originalWebDriver).resetInputState();
} else {
throw new UnsupportedOperationException("Wrapped WebDriver does not support reset input state");
}
}
}`
WebDriverFactory public static WebDriver create(int timeout) { WebDriver driver = null; for (int i = 0; i <= 1; i++) { try { if (i > 0) { Thread.sleep(2000); } switch (Environment.getValue("test.browser")) { case "firefox": throw new UnsupportedOperationException("FireFox not supported"); case "chrome": ChromeOptions options = new ChromeOptions(); options.addArguments("--disable-extensions"); options.addArguments("no-sandbox"); options.addArguments("/high-dpi-support=1"); options.addArguments("/force-device-scale-factor=1"); if ("true".equals(Environment.getValue("chrome.headless"))) { options.addArguments("--headless=new"); options.addArguments("window-size=1920,1080"); } driver = new WebDriverWrapper(new ChromeDriver(options)); break; case "ie": throw new UnsupportedOperationException("internet Explorer not supported"); default: throw new UnsupportedOperationException("specify supported browser"); } driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(timeout)); driver.manage().window().setSize(new Dimension(1920, 1080)); break; } catch (InterruptedException e) { System.out.println("interrupted initializing Driver"); throw new RuntimeException(e); } catch (Exception e) { e.printStackTrace(); log.info("Driver Couldn't be initialized in the attempt " + i); killDrivers(); } } return driver; }
Method to set Driver `public static void beforeSeleniumTestBase() { WebDriver driver = WebDriverFactory.create(30); driver.manage().window().maximize(); WebDriverAccessor.set(driver) WebDriverAccessor.get() }
WebDriverAccessor class WebDriverAccessor { static final ThreadLocal<WebDriver> webDriverThreadLocal = new ThreadLocal<WebDriver>() { }
static WebDriver get() {
return webDriverThreadLocal.get()
}
static WebDriver set(WebDriver webDriver) {
webDriverThreadLocal.set(webDriver)
}
static WebDriver remove() {
webDriverThreadLocal.remove()
}
}`
And Place in the test where It started to fail
WebDriver driver = WebDriverAccessor.get() Actions act = new Actions(driver) act.dragAndDrop(row, newplace).build().perform()
How can we reproduce the issue?
Shared method where it started to fail and most common preconditions
Relevant log output
org.openqa.selenium.json.JsonException: java.lang.reflect.InvocationTargetException
Build info: version: '4.21.0', revision: '79ed462ef4'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.10'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [id, actions {actions=[org.openqa.selenium.interactions.Sequence@6d21e89c]}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 125.0.6422.142, chrome: {chromedriverVersion: 125.0.6422.141 (..., userDataDir: AppData\L...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:57654}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: windows, proxy: Proxy(), se:cdp: ws://localhost:57654/devtoo..., se:cdpVersion: 125.0.6422.142, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
Session ID: id
at app//org.openqa.selenium.json.SimplePropertyDescriptor.lambda$getPropertyDescriptors$1(SimplePropertyDescriptor.java:106)
at app//org.openqa.selenium.json.JsonOutput.mapObject(JsonOutput.java:554)
at app//org.openqa.selenium.json.JsonOutput.lambda$new$31(JsonOutput.java:260)
at app//org.openqa.selenium.json.JsonOutput.write0(JsonOutput.java:409)
at app//org.openqa.selenium.json.JsonOutput.lambda$new$24(JsonOutput.java:222)
at [email protected]/java.util.HashMap.forEach(HashMap.java:1421)
at app//org.openqa.selenium.json.JsonOutput.lambda$new$25(JsonOutput.java:217)
at app//org.openqa.selenium.json.JsonOutput.write0(JsonOutput.java:409)
at app//org.openqa.selenium.json.JsonOutput.lambda$new$22(JsonOutput.java:204)
at [email protected]/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
at [email protected]/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
at [email protected]/java.util.LinkedList$LLSpliterator.forEachRemaining(LinkedList.java:1242)
at [email protected]/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at [email protected]/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at [email protected]/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at [email protected]/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at [email protected]/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at [email protected]/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
at app//org.openqa.selenium.json.JsonOutput.lambda$new$23(JsonOutput.java:204)
at app//org.openqa.selenium.json.JsonOutput.write0(JsonOutput.java:409)
at app//org.openqa.selenium.json.JsonOutput.lambda$new$24(JsonOutput.java:222)
at [email protected]/java.util.HashMap.forEach(HashMap.java:1421)
at app//org.openqa.selenium.json.JsonOutput.lambda$new$25(JsonOutput.java:217)
at app//org.openqa.selenium.json.JsonOutput.write0(JsonOutput.java:409)
at app//org.openqa.selenium.json.JsonOutput.convertUsingMethod(JsonOutput.java:518)
at app//org.openqa.selenium.json.JsonOutput.lambda$new$16(JsonOutput.java:182)
at app//org.openqa.selenium.json.JsonOutput.write0(JsonOutput.java:409)
at app//org.openqa.selenium.json.JsonOutput.lambda$new$22(JsonOutput.java:204)
at [email protected]/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
at [email protected]/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
at [email protected]/java.util.Iterator.forEachRemaining(Iterator.java:133)
at [email protected]/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845)
at [email protected]/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at [email protected]/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at [email protected]/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at [email protected]/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at [email protected]/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at [email protected]/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
at app//org.openqa.selenium.json.JsonOutput.lambda$new$23(JsonOutput.java:204)
at app//org.openqa.selenium.json.JsonOutput.write0(JsonOutput.java:409)
at app//org.openqa.selenium.json.JsonOutput.lambda$new$24(JsonOutput.java:222)
at [email protected]/java.util.Map.forEach(Map.java:713)
at app//org.openqa.selenium.json.JsonOutput.lambda$new$25(JsonOutput.java:217)
at app//org.openqa.selenium.json.JsonOutput.write0(JsonOutput.java:409)
at app//org.openqa.selenium.json.JsonOutput.write(JsonOutput.java:400)
at app//org.openqa.selenium.json.Json.toJson(Json.java:133)
at app//org.openqa.selenium.json.Json.toJson(Json.java:119)
at app//org.openqa.selenium.remote.codec.AbstractHttpCommandCodec.encode(AbstractHttpCommandCodec.java:245)
at app//org.openqa.selenium.remote.codec.AbstractHttpCommandCodec.encode(AbstractHttpCommandCodec.java:111)
at app//org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:178)
at app//org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:216)
at app//org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:174)
at app//org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:518)
at app//org.openqa.selenium.remote.RemoteWebDriver.perform(RemoteWebDriver.java:604)
at app//org.openqa.selenium.interactions.Actions$BuiltAction.perform(Actions.java:603)
at app//org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
at app//com.hli.qa.test.ui.common.model.organizations.LicenseTab.addLicense(LicenseTab.groovy:140)
at app//org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
at app//com.hli.qa.test.ui.common.tests.LicenseTest.code system and extension licensed - remove extension license for org - possible to just remove extension license(LicenseTest.groovy:430)
at [email protected]/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at [email protected]/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at [email protected]/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at [email protected]/java.lang.reflect.Method.invoke(Method.java:568)
at app//org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at app//org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at app//org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at app//org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at app//org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at app//org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at app//org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61)
at app//org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
at app//com.hli.test.common.junit.CASAuthorizationRule$1.evaluate(CASAuthorizationRule.groovy:32)
at app//org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
at app//com.hli.test.common.junit.KCAuthorizationRule$1.evaluate(KCAuthorizationRule.groovy:71)
at app//org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at app//org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at app//org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at app//org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at app//org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at app//org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at app//org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at app//org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at app//org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at app//org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at app//org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at app//org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at app//org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
at app//com.hli.test.common.junit.CASAuthorizationRule$1.evaluate(CASAuthorizationRule.groovy:32)
at app//org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
at app//com.hli.test.common.junit.KCAuthorizationRule$1.evaluate(KCAuthorizationRule.groovy:71)
at app//org.junit.rules.RunRules.evaluate(RunRules.java:20)
at app//org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at app//org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
at [email protected]/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at [email protected]/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at [email protected]/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at [email protected]/java.lang.reflect.Method.invoke(Method.java:568)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at jdk.proxy3/jdk.proxy3.$Proxy36.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run(TestWorker.java:176)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133)
at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
Suppressed: org.openqa.selenium.json.JsonException: Attempting to close incomplete json stream
Build info: version: '4.21.0', revision: '79ed462ef4'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.10'
Driver info: driver.version: RemoteWebDriver
at app//org.openqa.selenium.json.JsonOutput.close(JsonOutput.java:431)
at app//org.openqa.selenium.json.Json.toJson(Json.java:131)
... 70 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.openqa.selenium.json.SimplePropertyDescriptor.lambda$getPropertyDescriptors$1(SimplePropertyDescriptor.java:104)
... 115 more
Caused by: java.lang.UnsupportedOperationException: getShadowRoot
at org.openqa.selenium.WebElement.getShadowRoot(WebElement.java:274)
... 120 more
Operating System
Windows 11
Selenium version
4.21.0
What are the browser(s) and version(s) where you see this issue?
Chrome 125.0.6422.142
What are the browser driver(s) and version(s) where you see this issue?
chromedriverVersion: 125.0.6422.141
Are you using Selenium Grid?
No response
@vfedirko5, thank you for creating this issue. We will troubleshoot it as soon as we can.
Info for maintainers
Triage this issue by using labels.
If information is missing, add a helpful comment and then I-issue-template label.
If the issue is a question, add the I-question label.
If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.
If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C),
add the applicable G-* label, and it will provide the correct link and auto-close the
issue.
After troubleshooting the issue, please add the R-awaiting answer label.
Thank you!
Can you share the code in a GitHub repository? It is almost impossible to understand from the text above.
We need more information about this issue in order to troubleshoot.
Please turn on logging and re-run your code. Information on how to adjust logs for your language can be found in our Troubleshooting documentation.
Hello guys, Sorry for the delayed answer.
Not able to upload the project to GitHub or decompose it partially.
Here are the logs collected with the FINE level
Thank you! selenium4_issue_fine_logs.txt
This is the relevant piece of the logs.
2024-06-13 12:22:02 FINE Selenium [JdkHttpClient execute0] Executing request: (POST) /session/3fd7d691d31f2919380e65be4a30fa04/execute/sync
2024-06-13 12:22:02 FINE Selenium [JdkHttpClient execute0] Ending request (POST) /session/3fd7d691d31f2919380e65be4a30fa04/execute/sync in 7ms
2024-06-13 12:22:02 FINE Selenium [RemoteWebDriver] Executed: getElementAttribute (Response: SessionID: 3fd7d691d31f2919380e65be4a30fa04, State: success, Value: 1)
2024-06-13 12:22:02 FINE Selenium [RemoteWebDriver] Executing: actions [3fd7d691d31f2919380e65be4a30fa04, actions {actions=[org.openqa.selenium.interactions.Sequence@103d64a0]}]
2024-06-13 12:22:02 FINE Selenium [RemoteWebDriver] Executing: isElementDisplayed [3fd7d691d31f2919380e65be4a30fa04, isElementDisplayed {id=f.487D23111CBCA7F3286EE20258AD1BC7.d.180290C9CD5D9BD5A961B94746A931E4.e.111}]
2024-06-13 12:22:02 FINE Selenium [JdkHttpClient execute0] Executing request: (POST) /session/3fd7d691d31f2919380e65be4a30fa04/execute/sync
2024-06-13 12:22:02 FINE Selenium [JdkHttpClient execute0] Ending request (POST) /session/3fd7d691d31f2919380e65be4a30fa04/execute/sync in 9ms
2024-06-13 12:22:02 FINE Selenium [RemoteWebDriver] Executed: isElementDisplayed (Response: SessionID: 3fd7d691d31f2919380e65be4a30fa04, State: success, Value: true)
2024-06-13 12:22:02 FINE Selenium [RemoteWebDriver] Exception: actions java.lang.reflect.InvocationTargetException
Build info: version: '4.21.0', revision: '79ed462ef4'
It's weird to me that the log indicates that it isn't waiting after executing the actions before sending the isElementDisplayed... We can't actually get some of the interesting pieces from Java because of how it serializes things. Can you turn on driver logging: https://www.selenium.dev/documentation/webdriver/browsers/chrome/#log-output
I'm not sure why the return value of the Actions class wants to go through shadow root code to deserialize, I'd like to see what the driver itself is reporting.
@diemol @titusfortner Do you have any updates?
So this error is coming after the logs call isDisplayed(). Which... that method includes shadow root logic, so maybe if it is trying to deserialize the result? The log keeps going, though. Are you rescuing this error? It looks like it keeps going until it gets an element not found exception.
But yeah, there's a lot of code there for us to walk through it. What's the minimum code required to reproduce this issue? Can you remove all the extra capabilities, and remove the factory and just start a default driver that hits this issue?
@vfedirko5 i had a short look and from the stack i think your WebElementWrapper is the problem. There is no code to it, but i assume it extends WebElement, the code to serialize a WebElement is located in the RemoteWebElement. So the Json serializer does fallback to reflective mode, calling all declared methods.
Your WebElementWrapper must provide a public Map<String, Object> toJson() implementation. It might be best to delegate the call to the wrapped RemoteWebElement.
Thank you @joerg1985 ! Just tried with one test and it helps!
Will test during the week and will close the ticket! Thank you a lot!
This issue has been automatically locked since there has not been any recent activity since it was closed. Please open a new issue for related bugs.