chromedriver可执行文件未在路径中找到,但根据echo

时间:2020-11-06 00:06:19

标签: python selenium selenium-chromedriver

因此,我正在尝试首次使用chromedriver。我发现自己非常沮丧,因为我收到一个异常消息,告诉我chromedriver在路径中未找到,但实际上好像是在我的路径中。

  self.service.start()
  File "/Users/lukeanglin/opt/anaconda3/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home```

❯ echo $PATH
/Users/lukeanglin/opt/anaconda3/bin:/Users/lukeanglin/opt/anaconda3/bin:/Users/lukeanglin/opt/anaconda3/condabin:/anaconda3/bin:/Users/lukeanglin/miniconda3/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/lukeanglin/Desktop/Website/chromedriver:/Applications/VMware Fusion.app/Contents/Public:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands

我不确定我在这里做错了什么。任何帮助将不胜感激!

编辑:

这是我代码的相关部分。对一个有用的评论做一下,即可找到chromedriver。但是,我现在试图弄清为什么它没有执行。看来我的计算机认为它是恶意软件,因此我正设法解决该问题。

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import os
driver = webdriver.Chrome(executable_path="./chromedriver")

最终编辑:得益于两位评论者的帮助,我得以解决此问题。谢谢大家,您真棒!对于可能与恶意软件检测有相同问题的任何人,请在Mac上使用xattr -d。

1 个答案:

答案 0 :(得分:2)

我不知道代码的样子,但是据我所知,是当我将chromedriver和.py文件放在同一文件夹中并通过IDE运行它时,它可以正常工作,但是当我直接使用python运行它时,它给了我这个错误。所以你可以试试

from selenium import webdriver

driver = webdriver.Chrome(executable_path = r'path_to_chromedriver.exe')