小编典典

权限被拒绝:在python中运行Selenium Webdriver时出现“ geckodriver.log”

selenium

我已经在centos上安装了Firefox和Selenium。我正在使用Xvfb和pyvirtualdisplay打开浏览器。

当我尝试运行Selenium WebDriver时,我可以打开一个新显示,但是只要我这样做

browser = webdriver.Firefox()

我得到错误:

File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 134, in __init__
    self.service = Service(executable_path, log_path=log_path)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/firefox/service.py", line 45, in __init__
    log_file = open(log_path, "a+")
IOError: [Errno 13] Permission denied: 'geckodriver.log'

关于这里出了什么问题的任何线索吗?

编辑:克服权限错误后,我得到

Message: 'geckodriver' executable needs to be in PATH


阅读 1286

收藏
2020-06-26

共1个答案

小编典典

显然,这可能是由于您的Firefox和Selenium之间的不兼容所致。请尝试pip install --upgrade selenium,如果错误仍然存​​在,请尝试下载其他版本的Firefoxgecko驱动程序

关于消息:

'geckodriver' executable needs to be in PATH

您可以在脚本上设置驱动程序的路径:

ff_profile_dir = "/usr/local/selenium/webdriver/firefox"
ff_profile = selenium.webdriver.FirefoxProfile(profile_directory=ff_profile_dir)
driver = selenium.webdriver.Firefox(ff_profile)

或者,根据此答案,您可以在Unix系统上的bash兼容shell上运行:

export PATH=$PATH:/path/to/directory/of/executable/downloaded/in/previous/step

在Windows上,您将需要更新Path系统变量以手动或命令行将完整目录路径添加到可执行geckodriver(不要忘记在将可执行geckodriver添加到系统PATH中生效后重新启动系统)。其原理与Unix相同。

2020-06-26