selenium.common.exceptions.WebDriverException:消息:“chromedriver"可执行文件需要在 PATH 中 [英] selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH

查看:45
本文介绍了selenium.common.exceptions.WebDriverException:消息:“chromedriver"可执行文件需要在 PATH 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 python 和 selenium 自动化我的 Web 应用程序,我面临以下问题.

I am trying to automate my web application using the python and selenium, I am facing the below issue.

环境 - Mac/Python/SeleniumIDE - PyCharm

Environment - Mac/Python/Selenium IDE - PyCharm

selenium.common.exceptions.WebDriverException:消息:'chromedriver'可执行文件需要在 PATH 中.请参阅https://sites.google.com/a/chromium.org/chromedriver/家

selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

请帮我解决这个问题.

推荐答案

是的.因为您还没有通过 Selenium 驱动您的 Chrome 浏览器所需的 Chrome 二进制文件.

Yes. because you haven't pass the Chrome binary which required by Selenium to drive your Chrome browser.

您需要根据您的操作系统从以下 URL 下载二进制文件:-

You need to download binary as per your OS from below URL :-

https://chromedriver.storage.googleapis.com/index.html?path=2.32/

使用以下代码:-

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")

更改上面代码中chromedriver的路径

Change the path of chromedriver in above code

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/')

或者,您可以像这样使用 chromedriver 的直接路径:

Alternatively you can use a direct path to the chromedriver like this:

 driver = webdriver.Chrome('/path/to/chromedriver')

来源:

在 chrome 中运行 Selenium WebDriver python 绑定

这篇关于selenium.common.exceptions.WebDriverException:消息:“chromedriver"可执行文件需要在 PATH 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆