【问题标题】:error while exeutiing Selenium Python automation script执行 Selenium Python 自动化脚本时出错
【发布时间】: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盘并定义了路径。

【问题讨论】:

标签: python selenium automation


【解决方案1】:

只需替换这一行:

driver = webdriver.Firefox()  

收件人:

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

【讨论】:

    猜你喜欢
    • 2019-04-16
    • 1970-01-01
    • 1970-01-01
    • 2015-10-09
    • 2019-05-17
    • 2018-01-30
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多