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

时间:2018-07-20 22:45:49

标签: python selenium automation

我只是从Web复制了Selenium脚本,并试图学习Selenium python自动化。 这是脚本

/g

在运行时出现以下错误

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

出了什么问题? 我将geckodriver文件复制到c驱动器,并也定义了路径。

1 个答案:

答案 0 :(得分:1)

只需替换此行:

driver = webdriver.Firefox()  

收件人:

driver = webdriver.Firefox(executable_path = r'C:/Users/user***/Downloads/geckodriver-v0.20.1-win64/geckodriver.exe')