使用Selenium时出现java.net.SocketException: Connection reset错误求助
The Problem
I've been trying to run this Selenium automation script to access a target website, but I keep hitting a connection reset error. I've searched for solutions already but haven't found anything that works.
My Code
public static void main(String [] args) { System.setProperty("webdriver.chrome.driver","C:\\Users\\Ofima\\workspace\\OfimaWeb\\chromedriver.exe"); WebDriver driver= new ChromeDriver(); driver.get("http://ofimawebbeta.ofima.com/"); driver.manage().window().maximize(); driver.getTitle(); }
Error Log
Starting ChromeDriver (v2.9.248315) on port 41785
ene 19, 2018 9:48:49 AM org.openqa.selenium.remote.ProtocolHandshake createSession INFORMACIÓN: Detected dialect: OSS
Exception in thread "main" org.openqa.selenium.WebDriverException: java.net.SocketException: Connection reset
Build info: version: '3.8.0', revision: '924c4067df', time: '2017-11-30T11:37:19.049Z'
System info: host: 'PCPOF-021', ip: '10.72.4.128', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:325)
at OfimaWeb.cartera.main(cartera.java:23)
Caused by: java.net.SocketException: Connection reset
Solutions to Try
1. Match ChromeDriver, Chrome Browser, and Selenium Versions
Your ChromeDriver version is v2.9—that's extremely outdated (released around 2014), while your Selenium version is 3.8.0 (2017). This major version mismatch is almost certainly the root cause of the connection reset.
- First, check your installed Chrome version: Open Chrome → click the three dots in the top-right → Help → About Google Chrome to get the exact version number.
- Download a compatible ChromeDriver: ChromeDriver must match your Chrome browser version (e.g., Chrome 114.x needs ChromeDriver 114.x; aim for matching minor versions if possible).
- Ensure Selenium compatibility: Selenium 3.x supports ChromeDriver 2.31+, but it's best to use the latest ChromeDriver version that works with both your browser and Selenium 3.8.0.
2. Verify Network & Website Accessibility
- Manually visit
http://ofimawebbeta.ofima.com/in Chrome to confirm the site loads properly. Check if you need a proxy, VPN, or internal network access to reach it. - If you need a proxy, add it to your script:
ChromeOptions options = new ChromeOptions(); Proxy proxy = new Proxy(); proxy.setHttpProxy("your-proxy-address:port"); proxy.setSslProxy("your-proxy-address:port"); options.setCapability("proxy", proxy); WebDriver driver = new ChromeDriver(options);
3. Adjust ChromeDriver Launch Arguments
Try adding these flags to avoid connection issues:
ChromeOptions options = new ChromeOptions(); // Disable sandbox mode (helps on Windows environments) options.addArguments("--no-sandbox"); // Disable GPU acceleration to prevent rendering-related issues options.addArguments("--disable-gpu"); // Allow insecure content if the site uses HTTP with certificate warnings options.addArguments("--allow-running-insecure-content"); WebDriver driver = new ChromeDriver(options);
4. Check Firewall & Antivirus
Windows Firewall or your antivirus software might be blocking communication between ChromeDriver and Chrome. Temporarily disable them and run your script again to test if this fixes the problem.
内容的提问来源于stack exchange,提问作者Andrés Felipe Contreras Muñoz

