如何通过Chromedriver和Selenium启动Chrome及突发错误排查
Hey there! Let's break down your two questions clearly—first how to launch Chrome with Selenium and Chromedriver, then that frustrating out-of-the-blue error you're dealing with.
如何用Chromedriver与Selenium启动Chrome浏览器
Follow these straightforward steps to get up and running:
- Match Chrome and Chromedriver versions first: This is non-negotiable. Head to Chrome's settings → About Chrome to check your browser version, then download the exact matching Chromedriver version.
- Install Selenium: Run this command in your terminal/command prompt to install the library:
pip install selenium - Write the launch code:
- If you've added Chromedriver to your system's PATH (so your OS can find it anywhere), use this simple code:
from selenium import webdriver # Launch Chrome driver = webdriver.Chrome() # Navigate to a test site driver.get("https://www.example.com") - If you need to specify the exact path to your Chromedriver file (common if you don't want to mess with PATH):
from selenium import webdriver from selenium.webdriver.chrome.service import Service # Point to your Chromedriver location service = Service(executable_path="C:/path/to/your/chromedriver.exe") driver = webdriver.Chrome(service=service) driver.get("https://www.example.com") - Bonus tip for Selenium 4.6.0+: You don't even need to download Chromedriver manually anymore! Selenium will handle it automatically, so just
driver = webdriver.Chrome()works out of the box.
- If you've added Chromedriver to your system's PATH (so your OS can find it anywhere), use this simple code:
解决无代码修改却突然出现的Selenium/Chromedriver错误
From the traceback you shared, the error happens when importing webdriver from Selenium—here are the most likely fixes, since you didn't change any code:
- Chrome auto-updated in the background: This is the #1 culprit. Chrome often updates silently, making your old Chromedriver version incompatible. Fix it by:
- Checking your current Chrome version, then downloading the matching Chromedriver to replace the old one
- Switching to the auto-managed Chromedriver feature in Selenium 4.6+ (mentioned above) to avoid this issue entirely
- Corrupted Selenium installation: Your Anaconda environment's Selenium package might have gotten damaged. Uninstall and reinstall it with:
pip uninstall selenium pip install selenium - Permission issues: Sometimes system permission changes block Chromedriver from running. Right-click your Chromedriver file, go to Properties → Security, and make sure your user account has execute permissions. You can also try running your script as an administrator.
- Antivirus false positive: Some antivirus tools flag Chromedriver as malicious. Check your antivirus quarantine/block list, and add Chromedriver to its whitelist if it's there.
内容的提问来源于stack exchange,提问作者Austin Ju
相关产品推荐
相关产品推荐

