WebDriverException:即使'geckodriver'可执行文件也必须位于PATH中 [英] WebDriverException: 'geckodriver' executable needs to be in PATH even though it is

查看:125
本文介绍了WebDriverException:即使'geckodriver'可执行文件也必须位于PATH中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图让speder中的硒运行firefox.我当前的代码是

Trying to get firefox to run using selenium in spyder. My current code is

from selenium import webdriver
import os
os.environ["PATH"] += ":/usr/local/bin/geckodriver"
browser = webdriver.Firefox()

我仍然收到此错误:

runfile('/Users/mherl/Dropbox/AnacondaProjects/MWS/MWSSpyder/test.py', 
wdir='/Users/mherl/Dropbox/AnacondaProjects/MWS/MWSSpyder')
Traceback (most recent call last):

  File "<ipython-input-1-3f3f96ccf515>", line 1, in <module>

runfile('/Users/mherl/Dropbox/AnacondaProjects/MWS/MWSSpyder/test.py', 
wdir='/Users/mherl/Dropbox/AnacondaProjects/MWS/MWSSpyder')

  File "/Applications/anaconda3/lib/python3.6/site- 
  packages/spyder/utils/site/sitecustomize.py", line 705, in runfile
  execfile(filename, namespace)

  File "/Applications/anaconda3/lib/python3.6/site- 
  packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "/Users/mherl/Dropbox/AnacondaProjects/MWS/MWSSpyder/test.py", 
line 12, in <module>
  browser = webdriver.Firefox()

  File "/Applications/anaconda3/lib/python3.6/site- 
packages/selenium/webdriver/firefox/webdriver.py", line 152, in 
__init__
self.service.start()

  File "/Applications/anaconda3/lib/python3.6/site- 
packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)

WebDriverException: 'geckodriver' executable needs to be in PATH. 

即使gekodriver在该文件夹中.

Even though gekodriver is in that folder.

我也尝试过将路径导出到〜./bash_profile,现在看起来像这样.

I have also tried exporting the path to ~./bash_profile which looks like this right now.

Last login: Fri Apr 20 10:57:16 on ttys000
dhcp-54-85:~ mherl$ nano ./bash_profile
dhcp-54-85:~ mherl$ nano .bash_profile
  GNU nano 2.0.6             File: .bash_profile                      
Modified  


# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH

# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH

# added by Anaconda3 5.1.0 installer
export PATH="/Applications/anaconda3/bin:$PATH"

#added by mherl to show path to gekodriver
export PATH=$PATH:/usr/local/bin/gekodriver

我还在spyder中设置了当前路径:

I also have the current paths set in spyder:

/usr/local/bin
/Users/mherl/Dropbox/AnacondaProjects/MWS/MWSSpyder

其中的gekodriver

of which gekodriver is in

/usr/local/bin

我到处都看过,大多数人说如果它位于/usr/local/bin中,它应该会自动运行,但是即使我明确声明了路径,它仍然似乎找不到.

I have looked everywhere and most people say it should run automatically if it's in /usr/local/bin but it still can't seem to find it even when I explicitly state the path.

这很重要,这是一台运行High Sierra的Mac.

This is a mac running High Sierra if that's important.

推荐答案

此错误消息...

WebDriverException: 'geckodriver' executable needs to be in PATH. 

...表示在预期的默认位置找不到 GeckoDriver .

...implies that the GeckoDriver wasn't found in the expected default location.

在使用基于 MAC的系统时,您需要传递 Key executable_path 以及 Value 引用转到 GeckoDriver 绝对路径,如下所示:

As you are using MAC based System you need to pass the Key executable_path along with the Value referring to the absolute path of the GeckoDriver as follows :

from selenium import webdriver

browser = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver')

其他注意事项

确保满足以下条件:

Additional Consideration

Ensure the following :

  • GeckoDriver位于指定位置.
  • GeckoDriver对非root用户具有可执行权限.
  • 以非root用户身份执行@Test.

这篇关于WebDriverException:即使'geckodriver'可执行文件也必须位于PATH中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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