【问题标题】:Problem is selenium, python, beginner in coding问题是硒,python,编码初学者
【发布时间】:2022-01-17 08:49:48
【问题描述】:

我在尝试运行我的代码时收到此错误,请告诉我我能做什么。如果需要,我会在这里发布完整的代码。

Traceback (most recent call last):
  File "C:\Users\hp\Desktop\FB\GUI.py", line 104, in <module>
    main()
  File "C:\Users\hp\Desktop\FB\GUI.py", line 65, in main
    driver = webdriver.Chrome(options=options)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site- 
packages\selenium\webdriver\chrome\webdriver.py", line 70, in __init__
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
 File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 93, in __init__
RemoteWebDriver.__init__(
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 268, in __init__
self.start_session(capabilities, browser_profile)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 359, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 424, in execute
self.error_handler.check_response(response)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT 10.0.19042 x86_64)    

【问题讨论】:

标签: python selenium google-chrome selenium-webdriver


【解决方案1】:

您需要安装 chrome 驱动程序并告诉 selenium 在哪里可以找到它。 通过:

  • 更新您的 PATH
  • 在实例化新驱动程序时使用 executable_path

那么 安装铬 并告诉 chrome 驱动程序在哪里可以找到它。

【讨论】:

    【解决方案2】:

    该消息表明 chrome 驱动程序未安装或 Python 代码未找到。

    检查以下链接以设置 chrome 驱动程序:

    https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver

    最好的方法是从以下链接下载二进制文件:

    https://sites.google.com/a/chromium.org/chromedriver/

    完成后,您可以识别本地目录中存在的驱动程序的路径,如下所示:

    从硒导入网络驱动程序 从 selenium.webdriver.chrome.options 导入选项

    options = Options()
    options.binary_location = "C:\\Program Files\\Chrome\\chrome64_55.0.2883.75\\chrome.exe"
    driver = webdriver.Chrome(chrome_options = options, executable_path=r'C:\path\to\chromedriver.exe')
    driver.get('http://google.com/')
    print("Chrome Browser Invoked")
    driver.quit()
    

    【讨论】:

      【解决方案3】:

      您没有为您的浏览器安装驱动程序,或者 python 代码找不到它。在 Selenium 官方网站上,您可以找到安装相应驱动程序的详细说明:https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-17
        • 1970-01-01
        • 2015-11-16
        • 2021-02-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多