【已经解决】Python selenium.common.exceptions.WebDriverException
原创
©著作权归作者所有:来自51CTO博客作者mp624183768的原创作品,请联系作者获取转载授权,否则将追究法律责任
测试selenium报错
#!/usr/bin/python
# coding=utf-8
# author=He
from selenium import webdriver
browser = webdriver.Chrome()
browser.get("https://www.baidu.com")
print(browser.title)
browser.quit()
报错信息
/usr/bin/python3.5 /home/he/dev/python-test/run.py
Traceback (most recent call last):
File "/home/he/dev/python-test/run.py", line 7, in <module>
browser = webdriver.Chrome()
File "/usr/lib/python3/dist-packages/selenium/webdriver/chrome/webdriver.py", line 67, in __init__
desired_capabilities=desired_capabilities)
File "/usr/lib/python3/dist-packages/selenium/webdriver/remote/webdriver.py", line 91, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/lib/python3/dist-packages/selenium/webdriver/remote/webdriver.py", line 173, in start_session
'desiredCapabilities': desired_capabilities,
File "/usr/lib/python3/dist-packages/selenium/webdriver/remote/webdriver.py", line 233, in execute
self.error_handler.check_response(response)
File "/usr/lib/python3/dist-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: session not created exception: Chrome version must be >= 58.0.3029.0
(Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 4.9.0-deepin4-amd64 x86_64)
Process finished with exit code 1
浏览器驱动不存在或者驱动不适用当前版本
解决办法:
-chrome为例:
查看当前浏览器版本
输入chrome://help/
查看版本对应的驱动
https://sites.google.com/a/chromium.org/chromedriver/downloads
查看版本库
https://chromedriver.storage.googleapis.com/index.html
下载对应操作系统的文件
copy到he@he-PC:/usr/lib/chromium$ sudo cp ~/Desktop/chromedriver ./
或者用EveryThing 全局搜索chromedriver.exe 替换掉
再次运行
/usr/bin/python3.5 /home/he/dev/python-test/run.py
百度一下,你就知道
Process finished with exit code 0