【问题标题】:FileNotFound : [WinError 2] The system cannot find the file specified” Error while using selenium [duplicate]FileNotFound:[WinError 2]系统找不到指定的文件”使用硒时出错[重复]
【发布时间】:2023-04-02 19:25:02
【问题描述】:

我在 Windows pro 10 上并使用 Firefox 来执行 python selenium 程序。 尝试运行:

from selenium import webdriver
wb = webdriver.Firefox()
wb.get("https://stackoverflow.com")

出现以下错误(请忽略错误消息中的网络浏览器):

Traceback (most recent call last):
  File "C:\Users\dilri\AppData\Local\Programs\Python\Python36-32\lib\site-       packages\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Users\dilri\AppData\Local\Programs\Python\Python36-  32\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\Users\dilri\AppData\Local\Programs\Python\Python36-     32\lib\subprocess.py", line 990, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "H:\temp.py", line 2, in <module>
    driver = webdriver.Chrome()
  File "C:\Users\dilri\AppData\Local\Programs\Python\Python36-32\lib\site-   packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
    self.service.start()
  File "C:\Users\dilri\AppData\Local\Programs\Python\Python36-32\lib\site-  packages\selenium\webdriver\common\service.py", line 81, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver'     executable needs to be in PATH. Please see     https://sites.google.com/a/chromium.org/chromedriver/home

【问题讨论】:

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


    【解决方案1】:

    正如错误消息中明确提到的,首先安装适当的浏览器驱动程序并将其路径指定为system variable 路径。 就像我的情况一样:

    from selenium import webdriver
    driver_path = r"G:\Python\geckodriver.exe" #since on windows use raw strings 
    wb = webdriver.Firefox(executable_path=driver_path)
    
    # to check if it's working
    wb.get("https://stackoverflow.com")
    
    

    记住:驱动程序路径必须是原始字符串,因为我们在 Windows 上工作。 另外,请注意不要将文件名指定为 selenium.py

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-29
      • 2021-07-14
      • 1970-01-01
      • 2020-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多