NotADirectoryError: [Errno 20] Not a directory: '/home/ghost/automation/pwd/geckodriver' with GeckoDrriver Firefox and Selenium using Python3

NotADirectoryError: [Errno 20] Not a directory: '/home/ghost/automation/pwd/geckodriver' with GeckoDrriver Firefox and Selenium using Python3

我正在使用 pycharm 和我的 python

版本 3.6.7 pip 9.0.1

和selenium版本selenium-3.141.0 urllib3-1.24.1

我使用这个命令安装 selenium

pip3 install selenium  

然后我这样编码

from selenium import webdriver

driver = webdriver.Firefox("/home/ghost/automation/pwd/geckodriver")

driver.set_page_load_timeout(30)
driver.get("https://www.google.com/")
driver.maximize_window()
driver.implicitly_wait(120)
driver.get_screenshot_as_file("google.png")
driver.quit()

**当我运行这个我得到这个错误**

/home/ghost/PycharmProjects/try/venv/bin/python /home/ghost/PycharmProjects/try/open/testcas1.py
Traceback (most recent call last):
  File "/home/ghost/PycharmProjects/try/open/testcas1.py", line 3, in <module>
    driver = webdriver.Firefox("/home/ghost/automation/pwd/geckodriver")
  File "/home/ghost/PycharmProjects/try/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 151, in __init__
    firefox_profile = FirefoxProfile(firefox_profile)
  File "/home/ghost/PycharmProjects/try/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/firefox_profile.py", line 80, in __init__
    ignore=shutil.ignore_patterns("parent.lock", "lock", ".parentlock"))
  File "/usr/lib/python3.6/shutil.py", line 309, in copytree
    names = os.listdir(src)
NotADirectoryError: [Errno 20] Not a directory: '/home/ghost/automation/pwd/geckodriver'

Process finished with exit code 1

并且在这一行中 driver = webdriver.Firefox("/home/ghost/automation/pwd/geckodriver") 我的 geckodriver 和我的 geckodriver 的正确路径 版本是 0.23.0

这些答案对我没有帮助

简述

需要使用param键executable_path

详情

在使用 GeckoDriverFirefoxSelenium 时,您需要使用 Key executable_pathValue设置为绝对路径单引号内的 GeckoDriver 即带正斜杠的 '...'/ 作为 路径分隔符 如下:

driver = webdriver.Firefox(executable_path='/home/ghost/automation/pwd/geckodriver')

或使用默认位置

driver = webdriver.Firefox(executable_path=GeckoDriverManager(cache_valid_range=1).install())

我只是将 geckodriver.exe 文件放入我的主项目文件夹并将 link 标识为: driver=webdriver.Firefox("D:\Desktop\project") 没有 geckodriver,一切正常。

试试

  • "/home/ghost/automation/pwd"

  • "\\home\\ghost\\自动化\\pwd",
  • "\home\ghost\automation\pwd"

如果您使用 Atom IDE,您的问题可能是您 运行 一个带有脚本包的 .py 文件。它的工作方式与 cmd console

不同