RemoteWebDriver cannot be cast to HasDevTools
See original GitHub issue🐛 Bug Report
It’s not possible to use the DevTools with the RemoteDriver. I was told to use the HasDevTools Interface but it still not working when using a RemoteWebDriver (with a Grid)
java.lang.ClassCastException: class org.openqa.selenium.remote.RemoteWebDriver cannot be cast to class org.openqa.selenium.devtools.HasDevTools (org.openqa.selenium.remote.RemoteWebDriver and org.openqa.selenium.devtools.HasDevTools are in unnamed module of loader 'app')
Detailed steps to reproduce the behavior:
webDriver is RemoteWebDriver which is used in a SeleniumGrid Environment.
Java:
DevTools devTools = ((HasDevTools) webDriver).getDevTools();
Kotlin:
val devTools: DevTools = (webDriver as HasDevTools).devTools
Used Selenium Version: 4.0.0-rc-1 (also tested with beta-3 and beta-4)
Environment
OS: Ubuntu 21 Browser: Chrome Browser version: > 87 Browser Driver version: >87 Language Bindings version: Java
Issue Analytics
- State:
- Created 2 years ago
- Comments:37 (21 by maintainers)
Top 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 to ...
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 >HasDevTools - Selenium
Interface HasDevTools. All Known Implementing Classes: ChromeDriver , ChromiumDriver , EdgeDriver , FirefoxDriver. public interface HasDevTools ...
Read more >java.util.arraylist cannot be cast to org.json.simple.jsonarray
webDriver is RemoteWebDriver which is used in a SeleniumGrid Environment. Java: DevTools devTools = ((HasDevTools) webDriver).getDevTools();. Kotlin: val ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This issue actually refers to two different situations: “RemoteWebDriver cannot be cast to HasDevTools” and the “Unable to establish websocket connection to http…”. The commit fixes the latter. For the earlier, if you are facing that, please open a new issue with all the information requested in the template.
The fix allows the websocket connection when interacting with WebDriver BiDi or CDP over Grid, which seems to be the actual issue being faced by the OP.
Here is some context for the fix… In an conventional Grid setup, things work well because the Node receiving the WebDriver BiDi or CDP request, is running on the same host where the browser is running. This is not the case with Dynamic Grid (with Docker), because the Node is running in one container, and a new container is started to run the session. Therefore, the browser is running in one container, and the Node in a different one. That is why we need to forward one hop more the websocket request.
It is important to note, that doing WebDriver BiDi or CDP over Dynamic Grid is only supported when all components are running in Docker. A mix is not possible due to the network complexities of Docker.
This fix will be included in a bug release that will happen in the following days.
I have shared the issue comment above with Diego. He is the core contributor and expert for selenium-docker. He mentioned he is aware of the issue and will help on the same.