【发布时间】:2018-12-29 06:44:35
【问题描述】:
我刚刚从网上复制了 selenium 脚本并尝试学习 selenium python 自动化。 这是脚本
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.facebook.com")
运行时出现以下错误
Traceback (most recent call last):
File "C:\Users\hpatel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\hpatel\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 756, in __init__
restore_signals, start_new_session)
File "C:\Users\hpatel\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1155, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
在处理上述异常的过程中,又发生了一个异常:
Traceback (most recent call last):
File "C:\Users\hpatel\python\PythonLearn\src\Example1.py", line 8, in <module>
driver = webdriver.Firefox()
File "C:\Users\hpatel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 160, in __init__
self.service.start()
File "C:\Users\hpatel\AppData\Local\Programs\Python\Python37-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.
有什么问题? 我将geckodriver文件复制到c盘并定义了路径。
【问题讨论】:
-
啊,您需要指定 FireFox 二进制文件的路径。看看这个:stackoverflow.com/questions/25713824/…
标签: python selenium automation