How to resolve Unable to establish web socket connection exception in Selenium WebDriver with Chrome

Опубликовано: 04 Октябрь 2024
на канале: QACubicle
993
24

Welcome to my YouTube channel, In this video, I have explained that what is the root cause for the "Exception in thread "main" org.openqa.selenium.remote.http.ConnectionFailedException: Unable to establish websocket connection to http://localhost:54247/devtools/browser/...
" exception in Selenium WebDriver and how to fix it out.

Problem statement: While executing a basic Selenium program (Launch the Chrome browser and open any URL), the Chrome browser opens but is unable to launch the app URL, An exception is observed in the Eclipse console as : Exception is thread "main" org.openqa.selenium.remote.http.ConnectionFailedException: Unable to establish websocket connection to http://localhost:54247/devtools/browser/...

Root cause:
a. Some issues with WebSocket implementation of the http client why it is not able to understand the origin of the request.
b. Can also occur with of some random Selenium WebDriver version and Chrome browser version on your system.

Solution:
a. Create an object of ChromeOptions class, add addArguments "--remote-allow-origins=*" and pass it to ChromeDriver

// Code snippet //
ChromeOptions cop = new ChromeOptions();
cop.addArguments("--remote-allow-origins=*");
WebDriver driver = new ChromeDriver();

b. Use some latest Selenium WebDeriver version e.g. 4.11.0

Don't forget to subscribe to my channel -

/ @qacubicle
for more informative content on software testing, quality assurance, and test automation. Hit the notification bell to receive updates whenever we post new videos. If you have any questions or suggestions, feel free to leave a comment below.

Connect with me:
LinkedIn-   / kuldeep-k.  .
Email: [email protected]