Python Selenium winerror 2

时间:2018-03-19 16:27:25

标签: python selenium

我是Python的初学者,我尝试使用Selenium

我使用此视频教程https://www.youtube.com/watch?v=0vsswJooDe0安装了Selenium。我能够按照教程长达11分10秒。我尝试在多个位置保存脚本,包括在安装Selenium时添加的路径。

这是我试图运行的脚本

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("www.google.com")

这是出现的错误

 RESTART: C:/Users/cindy/AppData/Local/Programs/Python/Python36-32/sample.py 
Traceback (most recent call last):
  File "C:\Users\cindy\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
  File "C:\Users\cindy\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
  File "C:\Users\cindy\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 997, 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 "C:/Users/cindy/AppData/Local/Programs/Python/Python36-32/sample.py", line 5, in <module>
driver = webdriver.Firefox()
  File "C:\Users\cindy\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 152, in __init__
self.service.start()
  File "C:\Users\cindy\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

有人可以告诉我我做错了什么以及如何解决这个问题?谢谢!

1 个答案:

答案 0 :(得分:0)

Selenium依赖于特定于每个浏览器的其他绑定。首先,从here安装驱动程序,为您的特定操作系统选择下载。然后,将下载路径传递给构造函数:

driver = webdriver.Firefox("path/to/geckodriver/on/yourcomputer")