我正在使用pycharm和我的pythn

版本3.6.7点9.0.1

和硒版本selenium-3.141.0 urllib3-1.24.1

我使用此命令安装硒

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

这些答案对我没有帮助

https://stackoverflow.com/a/40399367/8337986
https://stackoverflow.com/a/42945346/8337986

最佳答案

在使用GeckoDriver,Firefox和Selenium时,您需要在单引号即executable_path中用正斜杠将'...'和设置为GeckoDriver绝对路径的Value用作路径分隔符,如下所示:

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

关于python - NotADirectoryError:[Errno 20]不是目录:使用Python3的GeckoDrriver Firefox和Selenium的'/home/ghost/automation/pwd/geckodriver',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53611499/

10-17 02:52