求助:无法通过Python3启动Selenium Safari WebDriver
Hey there! Let's troubleshoot this Safari + Selenium issue together. Even though you didn't share the exact error message, I've run into similar problems with Safari 11.x and Selenium 3.x before, so here are the most common fixes to try:
1. Verify WebDriver-Browser Version Match
Safari's WebDriver is tightly linked to the browser's version. Since you're on Safari 11.0.3, double-check that the WebDriver extension you installed matches this exact version:
- Open Safari > Preferences > Extensions
- Look at the version listed for SafariDriver
- If it doesn't align with 11.0.3, grab the matching version from Apple's official Safari WebDriver resources
2. Reset Remote Automation Permissions
Sometimes the "Allow Remote Automation" setting doesn't stick properly. Try resetting it:
- Close Safari completely
- Open Terminal and run this command:
defaults write com.apple.Safari IncludeDevelopMenu -bool true - Reopen Safari, go to the Develop menu, uncheck "Allow Remote Automation", then re-check it
- Quit and restart Safari one more time
3. Upgrade Selenium to a More Compatible Version
Selenium 3.10.0 is a bit outdated, and later releases fixed several Safari 11 compatibility bugs. Upgrade Selenium with this terminal command:pip install --upgrade selenium
Aim for version 3.141.0 or higher, which has improved support for older Safari versions.
4. Test with Minimal Working Code
Make sure your code is correctly initializing the Safari driver. Test with this minimal script first to rule out script-specific issues:
from selenium import webdriver # Initialize Safari driver driver = webdriver.Safari() # Navigate to a test page driver.get("https://www.google.com") # Print page title to confirm it works print(driver.title) # Close the browser driver.quit()
5. Check System Automation Permissions
On macOS, permission issues can block WebDriver from working:
- Open System Preferences > Security & Privacy > Privacy > Automation
- Ensure your terminal (or IDE, like PyCharm) is checked under "Allow the apps below to control your computer"
- Also confirm Safari is listed with the necessary permissions
If you can share the exact error message you're seeing, I can narrow this down even further!
内容的提问来源于stack exchange,提问作者Lumi Wang

