You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Selenium使用IEDriverServer启动IE失败:连接被拒问题求助

Fixing "Failed to connect to localhost" (Connection refused) when launching IE with Selenium WebDriver

Hey there, let’s work through this frustrating IE + Selenium connection issue together— I’ve dealt with similar roadblocks before, so here are targeted fixes that often resolve the java.net.ConnectException: Connection refused error:

  • Verify IEDriverServer & Selenium Version Compatibility
    This is the most common culprit! Make sure your IEDriverServer.exe version matches exactly with your Selenium Java client version, and aligns with your installed IE browser version. For example, if you’re using Selenium 3.141.59, download the corresponding IEDriverServer release. Also, try using the 32-bit IEDriverServer even on a 64-bit system— it tends to have fewer compatibility issues with IE.

  • Explicitly Set IEDriverServer Path
    Even if you added the driver’s folder to your system Path environment variable, sometimes the system doesn’t pick it up reliably. Try hardcoding the path in your code to eliminate this variable:

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.ie.InternetExplorerDriver;
    
    public class IETest {
        public static void main(String[] args) {
            // Replace with your actual IEDriverServer path
            System.setProperty("webdriver.ie.driver", "C:\\Drivers\\IEDriverServer.exe");
            WebDriver driver = new InternetExplorerDriver();
            driver.get("http://google.co.in");
            driver.quit();
        }
    }
    
  • Disable IE Enhanced Protected Mode
    Beyond the standard Protected Mode settings, check the "Enhanced Protected Mode" in IE’s advanced settings:

    1. Open IE → Go to Internet Options → Advanced tab
    2. Scroll down to the Security section
    3. Uncheck "Enable Enhanced Protected Mode"
    4. Restart IE and run your code again
  • Check IE Browser Bit Version
    Ensure the bit version (32/64) of your IE browser matches the IEDriverServer you’re using. If you’re running 64-bit IE but having issues, switch to the 32-bit version (look for "Internet Explorer (32-bit)" in your Start Menu) and use the 32-bit IEDriverServer.

  • Temporarily Disable Firewall/Antivirus
    Local firewalls or antivirus tools often block the connection between Selenium and IEDriverServer on localhost. Try temporarily disabling them, then run your test. If this fixes the issue, add IEDriverServer.exe to your security tool’s trusted applications list.

  • Reset IE Settings to Default
    Corrupted IE settings can interfere with the driver connection:

    1. Go to Internet Options → Advanced tab
    2. Click Reset → Check "Delete personal settings"
    3. Confirm the reset, then restart your computer before testing again
  • Specify a Custom Port for IEDriver
    Sometimes the default port used by IEDriver is occupied by another application. Try specifying an unused port in your code:

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.ie.InternetExplorerDriver;
    import org.openqa.selenium.ie.InternetExplorerOptions;
    
    public class IETest {
        public static void main(String[] args) {
            System.setProperty("webdriver.ie.driver", "C:\\Drivers\\IEDriverServer.exe");
            InternetExplorerOptions options = new InternetExplorerOptions();
            options.setCapability("ie.driver.port", 5556); // Use an unused port
            WebDriver driver = new InternetExplorerDriver(options);
            driver.get("http://google.co.in");
            driver.quit();
        }
    }
    

Give these steps a try in order— start with version compatibility and explicit path setting, as those fix most cases. Let me know if any of these resolve your issue!

内容的提问来源于stack exchange,提问作者srikanth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:25:59