Selenium使用IEDriverServer启动IE失败:连接被拒问题求助
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 yourIEDriverServer.exeversion 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 systemPathenvironment 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:- Open IE → Go to Internet Options → Advanced tab
- Scroll down to the Security section
- Uncheck "Enable Enhanced Protected Mode"
- 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, addIEDriverServer.exeto your security tool’s trusted applications list.Reset IE Settings to Default
Corrupted IE settings can interfere with the driver connection:- Go to Internet Options → Advanced tab
- Click Reset → Check "Delete personal settings"
- 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

