一、問題現象
運作testDemo.py,報
selenium.common.exceptions.WebDriverException: Message: ‘chromedriver’
executable needs to be in PATH. Please see
https://sites.google.com/a/chromium.org/chromedriver/home
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIyVGduV2YfNWawNCM38FdsYkRGZkRG9lcvx2bjxiNx8VZ6l2cs0TPR9EeRpWTyklaOBDOsJGcohVYsR2MMBjVtJWd0ckW65UbM5WOHJWa5kHT20ESjBjUIF2X0hXZ0xCMx81dvRWYoNHLrdEZwZ1Rh5WNXp1bwNjW1ZUba9VZwlHdssmch1mclRXY39CXldWYtlWPzNXZj9mcw1ycz9WL49zZuBnL4YzMyAzNyETMwMTOwAjMwIzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
詳情資訊:![]()
驅動版本ok,python中遇到“selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ ”的解決方法 C:\Python38\python.exe
E:/PycharmProjects/autotest_hyrobot/cases/baidu/testDemo.py Traceback
(most recent call last): File
“C:\Python38\lib\site-packages\selenium\webdriver\common\service.py”,
line 72, in start
self.process = subprocess.Popen(cmd, env=self.env, File “C:\Python38\lib\subprocess.py”, line 804, in init
errread, errwrite) = self._get_handles(stdin, stdout, stderr) File “C:\Python38\lib\subprocess.py”, line 1169, in _get_handles
c2pwrite = msvcrt.get_osfhandle(self._get_devnull()) File “C:\Python38\lib\subprocess.py”, line 952, in _get_devnull
self._devnull = os.open(os.devnull, os.O_RDWR) FileNotFoundError: [Errno 2] No such file or directory: ‘nul’
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
“E:/PycharmProjects/autotest_hyrobot/cases/baidu/testDemo.py”, line 5,
in
d = webdriver.Chrome(executable_path=\ File “C:\Python38\lib\site-packages\selenium\webdriver\chrome\webdriver.py”,
line 73, in init
self.service.start() File “C:\Python38\lib\site-packages\selenium\webdriver\common\service.py”,
line 81, in start
raise WebDriverException( selenium.common.exceptions.WebDriverException: Message:
‘chromedriver.exe’ executable needs to be in PATH. Please see
https://sites.google.com/a/chromium.org/chromedriver/home
Process finished with exit code 1
二:testDemo.py内容
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get("http://www.baidu.com")
time.sleep(3)
driver.quit()
三、解決方法
背景:浏覽器驅動版本與浏覽器版本一緻,驅動放在python安裝目錄下的,chrome路徑、python路徑均已加入環境變量path中且通過cmd确認路徑均有效(确認方法:1、在cmd中輸入chrome可以打開chrome浏覽器;2、在cmd中輸入chromedriver顯示驅動資訊)。
解決方法:未解決。。。(IE也是同樣的問題)
四、其他
Firefor浏覽器(版本為81.0.1)ok,使用浏覽器版本和驅動連結如下:
連結: https://pan.baidu.com/s/1V6nzSlpVUpC0qS0wdcfttg 提取碼: 9rmx