未知错误:chrome无法启动

时间:2017-11-06 17:14:37

标签: python selenium selenium-chromedriver

由于这个问题,我已经被困了几天,似乎无法找到解决方案。无论我做什么,我都无法让chromedriver在我的机器上工作。我已经尝试了几乎所有我能想象到的设置。列举几个:

  • Chrome 64位,Python 64位
  • Chrome 32位,Python 32位
  • Chrome 64位,Python 32位
  • Chrome 32位,Python 64位

我还尝试过不同版本的Chrome及其相应的chromedriver版本。我尝试过不同的硒早期版本,就是之前提到的所有设置。

对于实际情况,这是我当前的设置:

  • Windows 10 Professional x64
  • Python 3.6.3 64位
  • Selenium 3.7.0
  • 谷歌浏览器62.0.3202.75 64位
  • Chromedriver 2.33

我不会发布我的代码,因为无论我使用哪种代码,它都会失败。即使是最简单的最基本的代码启动chromedriver也行不通。此外,它适用于我的同事的机器。因此,为了给出一些背景信息,我在这里尝试了一些不起作用的代码片段:

from selenium import webdriver

webdriver.Chrome(executable_path="bin/chromedriver.exe")

我还尝试将chromedriver添加到我的PATH并启动chromedriver而没有任何参数,但这也不起作用。

我得到的错误就是这个:

selenium.common.exceptions.WebDriverException: Message: unknown error: chrome failed to start
  (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.15063 x86_64)

如果我使用详细/日志记录参数启动驱动程序,那么这里会生成日志:

[1.979][INFO]: COMMAND InitSession {
   "capabilities": {
      "alwaysMatch": {
         "browserName": "chrome",
         "goog:chromeOptions": {
            "args": [  ],
            "extensions": [  ]
         },
         "platformName": "any"
      },
      "firstMatch": [ {

      } ]
   },
   "desiredCapabilities": {
      "browserName": "chrome",
      "goog:chromeOptions": {
         "args": [  ],
         "extensions": [  ]
      },
      "platform": "ANY",
      "version": ""
   }
}
[1.985][INFO]: Populating Preferences file: {
   "alternate_error_pages": {
      "enabled": false
   },
   "autofill": {
      "enabled": false
   },
   "browser": {
      "check_default_browser": false
   },
   "distribution": {
      "import_bookmarks": false,
      "import_history": false,
      "import_search_engine": false,
      "make_chrome_default_for_user": false,
      "show_welcome_page": false,
      "skip_first_run_ui": true
   },
   "dns_prefetching": {
      "enabled": false
   },
   "profile": {
      "content_settings": {
         "pattern_pairs": {
            "https://*,*": {
               "media-stream": {
                  "audio": "Default",
                  "video": "Default"
               }
            }
         }
      },
      "default_content_setting_values": {
         "geolocation": 1
      },
      "default_content_settings": {
         "geolocation": 1,
         "mouselock": 1,
         "notifications": 1,
         "popups": 1,
         "ppapi-broker": 1
      },
      "password_manager_enabled": false
   },
   "safebrowsing": {
      "enabled": false
   },
   "search": {
      "suggest_enabled": false
   },
   "translate": {
      "enabled": false
   }
}
[1.989][INFO]: Populating Local State file: {
   "background_mode": {
      "enabled": false
   },
   "ssl": {
      "rev_checking": {
         "enabled": false
      }
   }
}
[2.004][INFO]: Cannot switch to US keyboard layout - some keys may be interpreted incorrectly
[2.004][INFO]: Launching chrome: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-background-networking --disable-browser-side-navigation --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-automation --enable-logging --force-fieldtrials=SiteIsolationExtensions/Control --ignore-certificate-errors --load-extension="C:\Users\OLIVIE~1.VER\AppData\Local\Temp\scoped_dir9668_31484\internal" --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=12606 --safebrowsing-disable-auto-update --test-type=webdriver --use-mock-keychain --user-data-dir="C:\Users\OLIVIE~1.VER\AppData\Local\Temp\scoped_dir9668_609" data:,
[2.035][INFO]: RESPONSE InitSession unknown error: chrome failed to start
[2.035][DEBUG]: Log type 'driver' lost 0 entries on destruction
[2.035][DEBUG]: Log type 'browser' lost 0 entries on destruction

我已经查看了几乎所有我能找到的类似问题,例如this onethis one,而且我遇到过的解决方案都没有帮助,它总是和我得到的错误相同。我已尝试过十几个不同的设置,但我遇到了同样的错误。

几个月前,我记得我在同一台机器上成功运行了另一个项目的chromedriver。

我想我已经提供了所有必要的信息,但如果我忘记了什么,请不要在评论中问我。

由于

2 个答案:

答案 0 :(得分:2)

错误表明全部 Cannot switch to US keyboard layout - some keys may be interpreted incorrectly 。此错误引发了更多错误:

[2.035][INFO]: RESPONSE InitSession unknown error: chrome failed to start
[2.035][DEBUG]: Log type 'driver' lost 0 entries on destruction
[2.035][DEBUG]: Log type 'browser' lost 0 entries on destruction

所以基本上这个错误不属于SeleniumChrome

以下是最好的solutions to your problem

更新:

由于您已摆脱错误Cannot switch to US keyboard layout - some keys may be interpreted incorrectly,但仍然看到 WebDriverException: Message: unknown error: chrome failed to start ,请按照以下步骤操作:

  1. 使用Chrome通过 Revo Uninstaller 卸载 Moderate Memory Scan ,以便清除不需要的注册表项。
  2. 在执行CCleaner之前和之后运行 Tests 工具,以清除所有操作系统杂务。
  3. Reboot 您的系统。
  4. Execute 您的Test

    driver=webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe')
    

答案 1 :(得分:1)

我最终经历了无数种不同的解决方案而没有结果,但最终似乎真正解决了以下问题:

  • 卸载Chrome
  • 浏览Windows注册表并删除名为{8A69D345-D564-463C-AFF1-A69D9E530F96}
  • 的每个键
  • 重新安装Chrome

在遵循DebanjanB's answer的解决方案后,我最终得到了此解决方案,无法再安装Chrome。搜索这个新问题后,我找到了this post

Remember to backup your registry before doing this.

完成此操作后,我可以重新安装Chrome并运行chromedriver。