org.openqa.selenium.remote.http.ConnectionFailedException: Unable to establish websocket connection
Asked Answered
L

3

5

Hey i have been tying to write a code that should login to a website, everything worked fine and then this happened "org.openqa.selenium.remote.http.ConnectionFailedException: Unable to establish websocket connection"

i tried searching for solutions here and added

`ChromeOptions options = new ChromeOptions();
      options.addArguments("--remote-allow-origins=*");
      options.addArguments("--no-sandbox");
      options.addArguments("--disable-dev-shm-usage")`

Still getting the same error im compleatly stuck i would love some help here is the whole code :

`package Testing;
import static org.testng.Assert.assertTrue;
import org.apache.mave.maven.Objects;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;



public class Testing2 {
  private WebDriver driver;
  private Objects obj;
  @BeforeMethod
    public void BeforeMethod() throws InterruptedException {
      ChromeOptions options = new ChromeOptions();
      options.addArguments("--remote-allow-origins=*");
      options.addArguments("--no-sandbox");
      options.addArguments("--disable-dev-shm-usage");
        driver = new ChromeDriver();
        driver.navigate().to("https://daatsolutions.info/jti/user-info/");
        driver.manage().window().maximize();
        obj = new Objects(driver);
        Thread.sleep(5000);
        System.out.println("---New Test---");
    }
     @Test
     public void firstry() {
         obj.im21();
         assertTrue(driver.getPageSource().contains("ואתם בפנים"));
     
     }
}
  `


Tired to add this : ChromeOptions options = new ChromeOptions(); options.addArguments("--remote-allow-origins=*"); options.addArguments("--no-sandbox"); options.addArguments("--disable-dev-shm-usage"); still getting the same error and cant reach the site

Lucchesi answered 14/3, 2023 at 11:7 Comment(0)
T
12

The answer can be found here: https://github.com/SeleniumHQ/selenium/issues/11750

This exception is related with Chrome 111 update.

I added the argument "--remote-allow-origins=*" and it's working for now.

public static ChromeDriver getChromeDriver() {
    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.addArguments("--start-maximized");
    chromeOptions.addArguments("--remote-allow-origins=*");
    return new ChromeDriver(chromeOptions);
}
Teucer answered 14/3, 2023 at 17:47 Comment(1)
Hey, i tried this, still the same errorLucchesi
C
0

Try this one

Add dependency

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-http-jdk-client</artifactId>
    <version>4.8.1</version>
</dependency>

And

System.setProperty("webdriver.http.factory", "jdk-http-client");

It works for me.

Celebrity answered 18/3, 2023 at 8:6 Comment(0)
V
0

System.setProperty("webdriver.chrome.driver", "./dvr/chromedriver.exe");

System.setProperty("webdriver.http.factory", "jdk-http-client");

it is working fine and add this dependency

Vernievernier answered 9/2 at 7:53 Comment(1)
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-http-jdk-client</artifactId> <version>4.5.0</version> </dependency>Vernievernier

© 2022 - 2024 — McMap. All rights reserved.