【问题标题】:Selenium opening geckdriver error: NotADirectoryError: [WinError 267] The directory name is invalid [duplicate]Selenium 打开 geckdriver 错误:NotADirectoryError: [WinError 267] 目录名无效 [重复]
【发布时间】:2021-10-27 21:00:45
【问题描述】:
import time
import pyautogui
import sys
from selenium import webdriver

tabTimer = 0


fileRun = __file__
fileRun = fileRun.replace("app.py", "geckodriver.exe")

print(fileRun)




stall  = input("enter filepath: ")

driver = webdriver.Firefox(fileRun)
driver.get("htpps://google.com")

每当我尝试打开 geckodriver 时,无论是使用下面使用的方法还是手动将文件路径输入为 r"",它无论出于何种原因都不起作用并生成以下错误。感谢您的帮助或建议,谢谢!

c:\Users\ellio\Desktop\main\app.py:22: DeprecationWarning: firefox_profile has been deprecated, please pass in an Options object
  driver = webdriver.Firefox(fileRun)
Traceback (most recent call last):
  File "c:\Users\ellio\Desktop\main\app.py", line 22, in <module>
    driver = webdriver.Firefox(fileRun)
  File "C:\Users\ellio\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 160, in __init__   
    firefox_profile = FirefoxProfile(firefox_profile)
  File "C:\Users\ellio\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\firefox\firefox_profile.py", line 74, in __init__
    shutil.copytree(self.profile_dir, newprof,
  File "C:\Users\ellio\AppData\Local\Programs\Python\Python39\lib\shutil.py", line 555, in copytree
    with os.scandir(src) as itr:
NotADirectoryError: [WinError 267] The directory name is invalid: 'c:\\Users\\ellio\\Desktop\\main\\geckodriver.exe'

【问题讨论】:

    标签: python python-3.x selenium-webdriver


    【解决方案1】:

    NotADirectoryError: [WinError 267]表示webriver的Firefox方法是在找目录,而不是文件路径。如果您查看堆栈跟踪,您会看到错误是由os.scandir 引发的。 os.scandir 只接受目录,不接受直接文件路径。

    如果你在路径的末尾省略 geckodriver.exe 应该没问题。

    【讨论】:

      猜你喜欢
      • 2019-01-20
      • 1970-01-01
      • 1970-01-01
      • 2018-09-30
      • 2017-11-20
      • 1970-01-01
      • 2021-02-06
      • 2021-06-12
      • 1970-01-01
      相关资源
      最近更新 更多