🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] 1. ChromeDriver与本地chrome浏览器的版本不一致 [SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 81](https://stackoverflow.com/questions/60296873/sessionnotcreatedexception-message-session-not-created-this-version-of-chrome) **解决方案:** 这是因为ChromeDriver与本地chrome浏览器的版本不一致导致 (1)ChromeDriver下载地址:[http://npm.taobao.org/mirrors/chromedriver/](http://npm.taobao.org/mirrors/chromedriver/) 下载到本地,解压 (2)找到自己的chromedriver安装位置,一般在/usr/local/bin(或者在/usr/bin)下,将新下载的chromedriver替换老版本的chromedriver <br /> 2. ChromeDriver 驱动文件添加到“环境变量”的Path 中 ``` Traceback (most recent call last): File "C:\Python37\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start stdin=PIPE) File "C:\Python37\lib\subprocess.py", line 709, in __init__ restore_signals, start_new_session) File "C:\Python37\lib\subprocess.py", line 997, in _execute_child startupinfo) FileNotFoundError: [WinError 2] 系统找不到指定的文件。 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "baidu_test.py", line 3, in <module> driver = webdriver.Chrome() File "C:\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__ self.service.start() File "C:\Python37\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home ``` **解决方案:** 需要将 Chrome 浏览器对应的 ChromeDriver 驱动文件添加到“环境变量”的Path 中。 <br /> **各浏览器驱动下载地址如下:** GeckoDriver(Firefox):https://github.com/mozilla/geckodriver/releases ChromeDriver(Chrome):https://sites.google.com/a/chromium.org/chromedriver/home IEDriverServer(IE):http://selenium-release.storage.googleapis.com/index.html OperaDriver(Opera):https://github.com/operasoftware/operachromiumdriver/releases MicrosoftWebDriver(Edge):https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver <br /> **(1)设置浏览器驱动** 设置浏览器的地址非常简单。 我们可以手动创建一个存放浏览器驱动的目录,如: C:\\driver , 将下载的浏览器驱动文件(例如:chromedriver、geckodriver)丢到该目录下。 我的电脑-->属性-->系统设置-->高级-->环境变量-->系统变量-->Path,将“C:\\driver”目录添加到Path的值中。 * Path * ;C:\\driver <br/> **(2)验证不同的浏览器驱动是否正常使用** ``` from selenium import webdriver driver = webdriver.Firefox() # Firefox浏览器 driver = webdriver.Chrome() # Chrome浏览器 driver = webdriver.Ie() # Internet Explorer浏览器 driver = webdriver.Edge() # Edge浏览器 driver = webdriver.Opera() # Opera浏览器 ```