让 Chrome 通过 Selenium 启动

问题描述

我在从 python 中的 selenium 获取 Chrome 浏览器实例时遇到问题.我使用的是 Windows 8.我已经下载了 chromedriver 二进制文件并将其添加到我的路径中,但在 Python 中出现以下错误:

I am having issues getting an instance of a Chrome browser from selenium in python. I'm using Windows 8. I have downloaded the chromedriver binary and added it to my path but I get the following error in Python:

selenium.common.exceptions.WebDriverException: Message: 'ChromeDriver executable needs to be available in the path.   

以下行出现此错误:

driver = webdriver.Chrome(executable_path='path	ochromedriver_win32_2.0')  


解决方案

两种设置方式,你搞混了.

Two ways to set it, you somehow mixed up.

  • chromedriver.exe 的路径放入 PATH(在 Windows 上),这样您的 PATH 设置是正确的,但是你需要调用默认构造函数.

  • Put the chromedriver.exe's path into PATH (on Windows), so your PATH setting is correct, but you need to call the default constructor.

driver = webdriver.Chrome()

webdriver.Chrome(executable_path='some path') 中指定路径.这里需要的是可执行文件的完整路径,而不是目录.

Specify the path in webdriver.Chrome(executable_path='some path'). Here you need the full path to the executable, not the directory.

webdriver.Chrome(executable_path=r'C:UsersHaranKumarDownloadschromedriver_win32_2.0chromedriver.exe')

选择你想要的任何一个.

Choose either one you want.

相关文章