我的设置:
- MacOS 10.12.3虚拟环境
- 我已经通过
pip install selenium
(3.3.1)安装了 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
必须说,executable_path
是在尝试在SO. bin文件中看到一些答案后添加的(geckodriver
是从命令行执行的,没有任何问题)。我该如何修复这个问题?
2条答案
按热度按时间um6iljoc1#
我已更改路径:
driver = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver')
至
driver = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver')
个(and我安装了Firefox浏览器,但我不确定是否相关)。
w41d8nur2#
根据需要使用权限
请参考此链接以了解权限
https://www.freecodecamp.org/news/how-to-change-file-permissions-with-the-chmod-command-on-linux/