[英]selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH
I am trying to automate my web application using the python and selenium, I am facing the below issue.我正在尝试使用 python 和 selenium 自动化我的 Web 应用程序,我面临以下问题。
Environment - Mac/Python/Selenium IDE - PyCharm环境 - Mac/Python/Selenium IDE - PyCharm
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. selenium.common.exceptions.WebDriverException: 消息:'chromedriver' 可执行文件需要在 PATH 中。 Please see https://sites.google.com/a/chromium.org/chromedriver/home请参阅https://sites.google.com/a/chromium.org/chromedriver/home
Please help me resolve this issue.请帮我解决这个问题。
Yes.是的。 because you haven't pass the Chrome binary which required by Selenium to drive your Chrome browser.因为您还没有通过 Selenium 所需的 Chrome 二进制文件来驱动您的 Chrome 浏览器。
You need to download binary as per your OS from below URL :-您需要根据您的操作系统从以下 URL 下载二进制文件:-
https://chromedriver.storage.googleapis.com/index.html?path=2.32/ https://chromedriver.storage.googleapis.com/index.html?path=2.32/
Use below code :-使用以下代码:-
import os
from selenium import webdriver
chromedriver = "/Users/adam/Downloads/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.get("http://stackoverflow.com")
Change the path of chromedriver in above code更改上面代码中chromedriver的路径
OR或者
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
cap = DesiredCapabilities.CHROME
cap = {'binary_location': /Users/adam/Downloads/chromedriver"}
driver = webdriver.Chrome(desired_capabilities=cap, executable_path="/Users/adam/Downloads/chromedriver")
driver.get('http://google.com/')
OR或者
Alternatively you can use a direct path to the chromedriver like this:或者,您可以像这样使用 chromedriver 的直接路径:
driver = webdriver.Chrome('/path/to/chromedriver')
Source:来源:
Running Selenium WebDriver python bindings in chrome 在 chrome 中运行 Selenium WebDriver python 绑定
You need to download the chromedriver
binary from ChromeDriver Download
page and place it anywhere within your system.您需要从ChromeDriver Download
页面下载chromedriver
二进制文件并将其放置在系统中的任何位置。 While you initiate the WebDriver
instance you need to mention the absolute path of the ChromeDriver
binary.当您启动WebDriver
实例时,您需要提及ChromeDriver
二进制文件的绝对路径。
On my Windows 8
system the following code block works perfect:在我的Windows 8
系统上,以下代码块完美运行:
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
At firsts you need to download chrome driver from https://sites.google.com/a/chromium.org/chromedriver/downloads then unarchive it.首先,您需要从https://sites.google.com/a/chromium.org/chromedriver/downloads下载 chrome 驱动程序,然后将其解压缩。 then add this file to params of enviroments.然后将此文件添加到环境参数中。 And then write driver = webdriver.Chrome('C:\\YourPathofChromeDriver\\chromedriver.exe')然后写 driver = webdriver.Chrome('C:\\YourPathofChromeDriver\\chromedriver.exe')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.