【问题标题】:How to fix these errors so I can finally use 'webdriver.Chrome()'? [duplicate]如何修复这些错误,以便我最终可以使用“webdriver.Chrome()”? [复制]
【发布时间】:2019-11-12 13:00:47
【问题描述】:

我想使用 python 在网页上“单击”一个按钮。我正在尝试使用 selenium 包(如本示例中所示 how_can_i_essentially_click_a_button_on_a_webpage/),但在运行代码后立即收到以下消息:

我真的不明白发生了什么。 如果可能的话,我将不胜感激。

from selenium import webdriver
browsre = webdriver.Chrome()
Traceback (most recent call last):
  File "C:\Users\pablo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "C:\Users\pablo\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\Users\pablo\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 990, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] El sistema no puede encontrar el archivo especificado

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    browsre = webdriver.Chrome()
  File "C:\Users\pablo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\pablo\AppData\Local\Programs\Python\Python36-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: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

【问题讨论】:

  • 你的问题是chromedriver' executable needs to be in PATH...

标签: python selenium selenium-webdriver webdriver


【解决方案1】:

调查

“chromedriver”可执行文件需要在 PATH 中

您的脚本似乎无法在PATH 下找到chromedriver.exe,因此您需要add the folder, containing the chromedriver.exe to your system PATH

如果您通过PyCharm 运行测试,您可以在运行/调试配置中执行相同操作:

最后但并非最不重要的一点是,您可以修改驱动程序初始化行以包含您的 chromedriver.exe 的完整路径

driver = webdriver.Chrome("c:\\path\\to\\chromedriver.exe")

参考资料:

【讨论】:

  • 效果很好,谢谢。
【解决方案2】:

您的 chromedriver.exe 位于何处?它是否位于您的测试中指定的路径中?

在你的代码中试试这个:

 browser = webdriver.Chrome('/path/to/chromedriver') 

【讨论】:

  • 这对你有用吗?如果是这样,你能接受这个作为答案吗? (点击答案旁边的“检查”图标)
  • 抱歉,这样不行。还是谢谢
猜你喜欢
  • 2020-11-08
  • 1970-01-01
  • 2019-11-01
  • 1970-01-01
  • 2020-01-04
  • 2017-10-11
  • 2015-04-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多