Linux虚拟机执行Selenium脚本:Chrome60/Firefox52遇驱动不支持异常求助
Let’s get straight to solving your Unsupported Driver Exception issue—this almost always boils down to a mismatch between your browser version and its corresponding WebDriver, plus a few environment checks specific to Linux. Here’s how to fix each browser:
Chrome 60 Troubleshooting
Chrome enforces strict version alignment between the browser and ChromeDriver. For Chrome 60, you need ChromeDriver version 2.31, 2.32, or 2.33—these are the only releases officially compatible with Chrome 60.
Step-by-Step Fix:
- First, confirm the mismatch by checking your current ChromeDriver version:
chromedriver --version - Uninstall any existing, incompatible ChromeDriver (delete it directly if it’s in your PATH, or use your package manager if installed that way).
- Download the correct ChromeDriver binary for your Linux architecture (32-bit or 64-bit) from the official ChromeDriver archive.
- Make the binary executable:
chmod +x chromedriver - Either add the ChromeDriver directory to your system
PATH, or explicitly specify its path in your Selenium script:- Python example:
from selenium import webdriver driver = webdriver.Chrome(executable_path='/path/to/your/chromedriver') - Java example:
System.setProperty("webdriver.chrome.driver", "/path/to/your/chromedriver"); WebDriver driver = new ChromeDriver();
- Python example:
- Verify Chrome is properly installed and has all dependencies: Run
google-chrome --versionto confirm it’s Chrome 60, then useldd google-chrometo check for missing libraries (install any gaps with your distro’s package manager, e.g.,apt install libxss1for Debian/Ubuntu).
Firefox 52 Troubleshooting
Firefox 52 relies on GeckoDriver (Mozilla dropped direct Selenium support in favor of GeckoDriver starting with Firefox 48). For Firefox 52, you need GeckoDriver version 0.14.0 to 0.16.0, paired with Selenium 3.4.0 or later.
Step-by-Step Fix:
- Check your current GeckoDriver and Selenium versions:
geckodriver --version- For Python:
pip show selenium - For Java: Check your build file (pom.xml/gradle) for the Selenium dependency version.
- For Python:
- If your Selenium version is older than 3.4.0, upgrade it:
- Python:
pip install selenium==3.4.0 - Java: Update your dependency to
org.seleniumhq.selenium:selenium-java:3.4.0.
- Python:
- Download the compatible GeckoDriver version (0.15.0 is a safe bet for Firefox 52) for your Linux architecture.
- Make the binary executable:
chmod +x geckodriver - Specify the GeckoDriver path in your script, and ensure Marionette mode is enabled (it’s default in Firefox 52, but explicit setting avoids edge cases):
- Python example:
from selenium import webdriver from selenium.webdriver.firefox.options import Options options = Options() options.add_argument('-marionette') driver = webdriver.Firefox(executable_path='/path/to/your/geckodriver', firefox_options=options) - Java example:
System.setProperty("webdriver.gecko.driver", "/path/to/your/geckodriver"); WebDriver driver = new FirefoxDriver();
- Python example:
- Check Firefox dependencies with
ldd firefoxand install any missing libraries (e.g.,apt install libgtk-3-0for Debian/Ubuntu).
Quick Final Checks
- Ensure your Linux VM has the necessary display support: Even if running headless, you might need
xvfbto simulate a display—install it withapt install xvfband run your script viaxvfb-run python your_script.pyif needed. - Double-check that your browser versions are exactly Chrome 60 and Firefox 52 (minor version mismatches can still trigger compatibility issues).
内容的提问来源于stack exchange,提问作者Priyanka

