之前用selenium練習過一些web頁面的測試,對chrome瀏覽器和相應的驅動安裝過,可以正常使用。
但今天再次運行一些打開網頁的測試程序時,出現報錯:
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: Chrome version must be between 70 and 73
(Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.17763 x86_64)
如圖:
解決辦法:
1.檢查當前chrome瀏覽器版本為75.0.3770.142
2.百度:chrome75 對應的driver下載安裝,找到對應的版本為75.0.3770.8 ,參考文章為:https://blog.csdn.net/fox990152806/article/details/91881361
3.下載ChromeDriver,地址為:https://npm.taobao.org/mirrors/chromedriver/
下載完成后,解壓將chromedriver.exe文件放在python路徑下和chrome瀏覽器的根目錄下:
4.配置環境變量
5.驗證安裝成功否
運行下面代碼,能夠正常打開百度頁面,說明安裝成功。
from selenium import webdriver driver = webdriver.Chrome() driver.get('http://www.baidu.com')