'How to resolve java.net.SocketException: Connection reset exception in java with selenium?

When I am trying to driver.close() then I can get:

java.net.SocketException: Connection reset exception.

How to resolve it?

I'm writting a code like this:

driver.findElement(By.xpath("//*[text()='Log Out']")).click();
driver.close();


Solution 1:[1]

You have version problems

  1. Check your chromedriver version
  2. Check your chrome version
  3. Check your selenium version

They all should be compatible with each other

For example, if you are using chrome browser version 'Version 95.0.4638.69' you should have the same version for chromedriver.

Solution 2:[2]

To get rid of the residual chores generated during the test execution and interfere in your next test execution, instead of driver.close() always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Norayr Sargsyan
Solution 2 undetected Selenium