在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的安裝路徑。