Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
NotDirectoryError:[Errno 20]不是目录:'/home/ghost/automation/pwd/geckodriver';使用GeckoDrriver Firefox和Selenium使用Python3_Python_Selenium_Firefox_Selenium Webdriver_Geckodriver - Fatal编程技术网

NotDirectoryError:[Errno 20]不是目录:'/home/ghost/automation/pwd/geckodriver';使用GeckoDrriver Firefox和Selenium使用Python3

NotDirectoryError:[Errno 20]不是目录:'/home/ghost/automation/pwd/geckodriver';使用GeckoDrriver Firefox和Selenium使用Python3,python,selenium,firefox,selenium-webdriver,geckodriver,Python,Selenium,Firefox,Selenium Webdriver,Geckodriver,我在用pycharm和我的pythn 版本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_

我在用pycharm和我的pythn

版本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
/home/ghost/PycharmProjects/try/venv/bin/python/home/ghost/PycharmProjects/try/open/testcas1.py
回溯(最近一次呼叫最后一次):
文件“/home/ghost/PycharmProjects/try/open/testcas1.py”,第3行,在
driver=webdriver.Firefox(“/home/ghost/automation/pwd/geckodriver”)
文件“/home/ghost/PycharmProjects/try/venv/lib/python3.6/site packages/selenium/webdriver/firefox/webdriver.py”,第151行,在__
firefox\u profile=FirefoxProfile(firefox\u profile)
文件“/home/ghost/PycharmProjects/try/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/firefox_profile.py”,第80行,在__
ignore=shutil.ignore_模式(“parent.lock”、“lock”、“parentlock”))
copytree中的文件“/usr/lib/python3.6/shutil.py”,第309行
name=os.listdir(src)
NotDirectoryError:[Errno 20]不是目录:'/home/ghost/automation/pwd/geckodriver'
进程已完成,退出代码为1
在这一行中,
driver=webdriver.Firefox(“/home/ghost/automation/pwd/geckodriver”)
my
geckodriver的正确路径
版本为0.23.0

这些答案对我没有帮助

简而言之 需要使用参数键
可执行路径

详细地 在使用GeckoDriver、Firefox和Selenium时,需要使用键
可执行路径
和设置为GeckoDriver绝对路径的值(在单引号内),即带正斜杠的
“…”
,即
/
作为路径分隔符,如下所示:

driver = webdriver.Firefox(executable_path='/home/ghost/automation/pwd/geckodriver')
或者使用默认位置

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

我只是将geckodriver.exe文件放在我的主项目文件夹中,并将链接标识为:
driver=webdriver.Firefox(“D:\Desktop\project”)
没有geckodriver,一切正常

试一试

  • “/home/ghost/automation/pwd”

  • “\\home\\ghost\\automation\\pwd”
  • “\home\ghost\automation\pwd”

如果您使用Atom IDE,那么您的问题可能是使用脚本包运行
.py
文件。它的工作原理与cmd控制台不同

@DebanjanB
/
是正斜杠,而不是反斜杠。。。双引号的作用与单引号相同,因此没有必要选择单引号。