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
执行Selenium Python自动化脚本时出错_Python_Selenium_Automation - Fatal编程技术网

执行Selenium Python自动化脚本时出错

执行Selenium Python自动化脚本时出错,python,selenium,automation,Python,Selenium,Automation,我刚刚从web上复制了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):

我刚刚从web上复制了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. 
回溯(最近一次呼叫最后一次):
文件“C:\Users\hpatel\python\PythonLearn\src\Example1.py”,第8行,在
driver=webdriver.Firefox()
文件“C:\Users\hpatel\AppData\Local\Programs\Python\Python37-32\lib\site packages\selenium\webdriver\firefox\webdriver.py”,第160行,在\uu init中__
self.service.start()
文件“C:\Users\hpatel\AppData\Local\Programs\Python\Python37-32\lib\site packages\selenium\webdriver\common\service.py”,第83行,在开始处
os.path.basename(self.path)、self.start\u错误消息)
selenium.common.exceptions.WebDriverException:消息:“geckodriver”可执行文件需要位于路径中。
问题是什么?
我将geckodriver文件复制到c驱动器并定义了路径。

只需替换这一行:

driver = webdriver.Firefox()  
致:


啊,您需要指定FireFox二进制文件的路径。看看这个:
driver = webdriver.Firefox(executable_path = r'C:/Users/user***/Downloads/geckodriver-v0.20.1-win64/geckodriver.exe')