selenium:'geckodriver'可执行文件可能具有错误的权限

时间:2017-03-20 06:37:23

标签: python selenium intellij-idea geckodriver

我的设置:

  • MacOS 10.12.3虚拟环境
  • 我通过pip install selenium(3.3.1)installed selenium。
  • 我通过brew install geckodriver 0.15.0
  • 安装了geckodriver

尝试在intelliJ IDE中运行以下code

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox(executable_path='/usr/local/opt/geckodriver')
driver.get("https://google.com")
elem = driver.find_element_by_name("q")

并从第4行(driver = webdriver...)抛出异常:

Traceback (most recent call last):
  File "/Users/itayb/test/main.py", line 4, in <module>
    driver = webdriver.Firefox(executable_path='/usr/local/opt/geckodriver')
  File "/Users/itayb/test/venv/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 145, in __init__
    self.service.start()
  File "/Users/itayb/test/venv/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 86, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable may have wrong permissions. 


Process finished with exit code 1

必须说在尝试查看某些答案here in SO后添加了executable_path。 bin文件(geckodriver从命令行执行没有任何问题)。 我该如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

我改变了道路:

driver = webdriver.Firefox(executable_path='/usr/local/opt/geckodriver')

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

(并安装了Firefox浏览器,但我不确定是否相关)。