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

Python-Selenium启动IE浏览器报错,Java-Selenium同款脚本正常

Troubleshooting Selenium IE Launch Issues in Python/PyCharm (Works in Java/Eclipse)

Hey there! Let’s break down why your Python/PyCharm setup is failing to launch Internet Explorer with Selenium, even though the same driver works perfectly in Java/Eclipse. I’ve debugged similar issues before, so here are the most common fixes to try:

1. Check 32-bit/64-bit Mismatch Between Python and IE Driver

IE Driver comes in both 32-bit and 64-bit variants. It’s possible your Java environment aligns with the driver’s architecture, but your Python installation doesn’t. For example:

  • If you’re running 32-bit Python, using a 64-bit IE Driver will cause compatibility errors.

Fix:

  • Verify your Python architecture: Open a command prompt and run python --version (look for "32-bit" or "64-bit" in the output).
  • Download the matching IE Driver version (32/64-bit) and replace your current driver file. Alternatively, switch to a Python version that matches your driver’s architecture.

2. Standardize IE’s Protected Mode Settings

Selenium requires that all security zones (Internet, Local Intranet, Trusted Sites, Restricted Sites) in IE have the same Protected Mode status—either all enabled or all disabled. Java might have inherited a pre-configured setup, while your Python environment is hitting this restriction.

Fix:

  1. Open Internet Explorer → Go to Tools > Internet Options > Security tab.
  2. For each of the four zones, check (or uncheck) the "Enable Protected Mode" box to make them identical.
  3. Restart IE and re-run your Python script.

3. Run PyCharm with Administrator Privileges

Sometimes, PyCharm lacks the necessary permissions to interact with IE’s driver, while Eclipse was launched with admin rights (allowing it to work).

Fix:
Right-click the PyCharm shortcut and select "Run as administrator", then execute your Selenium script again.

4. Adjust Selenium Version for Python

Your Python Selenium version might be incompatible with the IE Driver. Newer Selenium versions have phased out IE support, while older versions are more stable for this browser.

Fix:

  • Uninstall your current Selenium version: pip uninstall selenium
  • Install a stable, IE-compatible version: pip install selenium==3.141.0 (this version has robust IE support)

5. Verify IE Driver Path Configuration

Even if you’re using the same driver file, Python might not be locating it correctly:

  • The driver might not be in your system’s PATH environment variable.
  • Your PyCharm working directory might be different, breaking relative path references to the driver.

Fix:

  • Add the folder containing IEDriverServer.exe to your system PATH.
  • Or, explicitly specify the absolute path to the driver in your script:
    from selenium import webdriver
    # Replace with your actual driver path
    driver = webdriver.Ie(executable_path=r"C:\Users\YourName\Downloads\IEDriverServer.exe")
    
  • Check PyCharm’s run configuration: Ensure the "Working directory" matches the folder where your script is stored.

6. Set IE’s Zoom Level to 100%

Selenium requires IE’s zoom level to be exactly 100%—any other setting will cause launch failures.

Fix:
Open IE → Go to View > Zoom and select 100%. Restart the browser before testing again.

If none of these fixes resolve the issue, sharing the exact error message from PyCharm will help narrow down the problem further!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 08:14:26