我的设置:
pip install selenium
(3.3.1)installed selenium。brew install geckodriver
0.15.0 尝试在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
从命令行执行没有任何问题)。
我该如何解决这个问题?
答案 0 :(得分:3)
我改变了道路:
driver = webdriver.Firefox(executable_path='/usr/local/opt/geckodriver')
到
driver = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver')
(并安装了Firefox浏览器,但我不确定是否相关)。