Anaconda环境设置Selenium的浏览器驱动程序

在windows中用anaconda环境开发测试Selenium中报错:

Traceback (most recent call last):
  File "D:\Anaconda3\envs\myenv36\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "D:\Anaconda3\envs\myenv36\lib\subprocess.py", line 729, in __init__
    restore_signals, start_new_session)
  File "D:\Anaconda3\envs\myenv36\lib\subprocess.py", line 1017, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:/share/python/selenium/test_baidu.py", line 3, in <module>
    driver = webdriver.Chrome()
  File "D:\Anaconda3\envs\myenv36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "D:\Anaconda3\envs\myenv36\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

根据错误提示信息,selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH
得知,chromedrive的驱动程序不存在,需要将驱动程序下载并添加到环境变量PATH中。

各个浏览器的下载驱动程序地址
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/

由于我本地的python运行环境是Anaconda的虚拟配置环境env环境,所以把下载的驱动chromedrive.exe程序放到D:/Anaconda3/envs/myenv36下, 具体参考你anaconda的安装路径。

posted @ 2020-10-23 16:17  phper-liunian  阅读(1139)  评论(0编辑  收藏  举报