【问题标题】:Getting Exceptions when using Selenium to open browser [duplicate]使用 Selenium 打开浏览器时出现异常 [重复]
【发布时间】:2018-04-11 19:01:58
【问题描述】:

我正在使用 python IDLE,执行以下操作后我收到此导入错误

>>> from selenium import webdriver
>>> browser=webdriver.Firefox()


Traceback (most recent call last):
  File "C:\Users\saish\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Users\saish\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "C:\Users\saish\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1224, 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 "<pyshell#18>", line 1, in <module>
    browser=webdriver.Firefox()
  File "C:\Users\saish\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 144, in __init__
    self.service.start()
  File "C:\Users\saish\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

【问题讨论】:

    标签: python python-2.7 selenium scripting automation


    【解决方案1】:

    你的例外很明显:

    WebDriverException:消息:'geckodriver' 可执行文件需要在 路径。

    您必须指定 geckodriver 的路径:

    driver = webdriver.Firefox(executable_path=r'/patToYour/geckodriver')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 2017-05-13
      • 2021-12-25
      • 1970-01-01
      • 2020-08-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多