question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[🐛 Bug]: org.openqa.selenium.remote.RemoteWebDriver$ByteBuddy$RwtMl7Wf cannot be cast to org.openqa.selenium.devtools.HasDevTools

See original GitHub issue

What happened?

I am running latest selenium-docker image:

sudo docker run -d -p 4444:4444 --shm-size="2g" -e SCREEN_WIDTH=1280 -e SCREEN_HEIGHT=720 selenium/standalone-chrome:4.1.0-20211209

In my Java application I have the following code snippet that throws ClassCastException:

ChromeOptions options = new ChromeOptions();
String driverUrl = "http://127.0.0.1:4444/wd/hub";
WebDriver driver = new RemoteWebDriver(new URL(driverUrl), options);
driver = new Augmenter().augment(driver);
DevTools devTools = ((HasDevTools) driver).getDevTools();
devTools.createSession();

As soon as the HasDevTools cast is attempted, I am getting:

org.openqa.selenium.remote.RemoteWebDriver$ByteBuddy$RwtMl7Wf cannot be cast to org.openqa.selenium.devtools.HasDevTools: java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebDriver$ByteBuddy$RwtMl7Wf cannot be cast to org.openqa.selenium.devtools.HasDevTools

I have carefully reviewed all the similar issues, but none of them seems to have concluded on this particular bug.

My relevant grade dependency is:

implementation 'org.seleniumhq.selenium:selenium-java:4.1.0'
implementation 'org.seleniumhq.selenium:selenium-devtools-v94:4.1.0'

My JDK is:

OS Version: 4.14.252-195.483.amzn2.x86_64 Java Name: OpenJDK 64-Bit Server VM Java Vendor: Oracle Corporation Java Version: 9.0.4 Java VM Version: 9.0.4+11

How can we reproduce the issue?

ChromeOptions options = new ChromeOptions();
String driverUrl = "http://127.0.0.1:4444/wd/hub";
WebDriver driver = new RemoteWebDriver(new URL(driverUrl), options);
driver = new Augmenter().augment(driver);
DevTools devTools = ((HasDevTools) driver).getDevTools();
devTools.createSession();

Relevant log output

2021-12-10      17:04:26        UTC     comment server  INFO    200     -       Tricky cast     _defaultVHost_  -       -       30.728  -       -       -       -       -       -       -       -       -       -       -       -       -
       -       -       -       -       -       -       -       -       -       -       -       -
2021-12-10      17:04:26        UTC     comment server  ERROR   500     -       Error initializing stack: org.openqa.selenium.remote.RemoteWebDriver$ByteBuddy$RwtMl7Wf cannot be cast to org.openqa.selenium.devtools.HasDevTools: java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebDriver$ByteBuddy$RwtMl7Wf cannot be cast to org.openqa.selenium.devtools.HasDevTools|at com.mycompany.blah.Foo.lambda$new$3(Foo.java:291)|at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(Unknown Source)|at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)|at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)|at java.base/java.lang.Thread.run(Unknown Source)|    _defaultVHost_  -       -       30.73   -

Operating System

Amazon Linux

Selenium version

4.1.0

What are the browser(s) and version(s) where you see this issue?

Chrome

What are the browser driver(s) and version(s) where you see this issue?

the one in your docker image

Are you using Selenium Grid?

4.1.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jhainzlschmidcommented, Feb 10, 2022

Confirming the fix: by adding the below to my build.gradle shadow related configuration, the issue is now gone because the services files are properly merged:

plugins {
    id 'java'
    id 'com.github.johnrengelman.shadow' version '5.2.0'
}

// dependencies, etc.

shadowJar  {
    mergeServiceFiles()
}

Thank you very much!

For the people using Maven: You need to use the maven shade plugin (maven assembly won’t work) and configure a ServicesResourceTransformer. Heres an example maven shade configuration for an executable uber jar:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>YourMainClass</mainClass>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
0reactions
github-actions[bot]commented, Mar 13, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

creating a devtools session with selenium 4 using ...
remote.RemoteWebDriver cannot be cast to class org.openqa.selenium.chrome.ChromeDriver when running: scenarioContext.setDevTools(((ChromeDriver) ...
Read more >
java.lang.ClassCastException: org.openqa.selenium.remote ...
I am getting below error while taking a screenshot. java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebDriver cannot be cast ...
Read more >
RemoteWebDriver cannot be cast to org.openqa.selenium ...
When I try to cast it to I get: java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebDriver cannot be cast to org.openqa.selenium.
Read more >
Class ChromeDriver - Selenium
Nested Class Summary. Nested classes/interfaces inherited from class org.openqa.selenium.remote.RemoteWebDriver · RemoteWebDriver.
Read more >
How to fix the 'ShadowRoot cannot be cast to org ... - YouTube
openqa. selenium.WebElement' error in selenium ?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found