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

zzzyeukh  于 2022-11-01  发布在  其他
关注(0)|答案(2)|浏览(103)

我的设置:

  • 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是从命令行执行的,没有任何问题)。我该如何修复这个问题?

um6iljoc

um6iljoc1#

我已更改路径:
driver = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver')

driver = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver')
(and我安装了Firefox浏览器,但我不确定是否相关)。

w41d8nur

w41d8nur2#

根据需要使用权限

sudo chmod 777 /usr/local/opt/geckodriver

请参考此链接以了解权限
https://www.freecodecamp.org/news/how-to-change-file-permissions-with-the-chmod-command-on-linux/

相关问题