WebDriverException:消息:未知错误:带有ChromeDriver Selenium和Python的C:/.../ Chrome / Application / chrome.exe没有chrome二进制文件

时间:2018-11-03 13:11:37

标签: python selenium google-chrome selenium-webdriver selenium-chromedriver

这里有Python新手...

Windows 7 x64和Python 3.7

我已经安装了Selenium和Chrome Webdriver。我正在使用:

$sig = '
[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")] public static extern int SetForegroundWindow(IntPtr hwnd);'
$type = Add-Type -MemberDefinition $sig -Name WindowAPI -PassThru
[IntPtr]$handleConsole = (Get-Process -Id $pid).MainWindowHandle
[void]$type::ShowWindowAsync($handleConsole, 4);[void]$type::SetForegroundWindow($handleConsole)

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()

$Form                            = New-Object system.Windows.Forms.Form
$Form.ClientSize                 = '446,266'
$Form.text                       = "Form"
$Form.TopMost                    = $false

$Form.Add_Shown({
 $global:handleForm = (Get-Process -Id $pid).MainWindowHandle
})

$Button1                         = New-Object system.Windows.Forms.Button
$Button1.text                    = "Clone ad-USer"
$Button1.width                   = 60
$Button1.height                  = 30
$Button1.location                = New-Object System.Drawing.Point(75,29)
$Button1.Font                    = 'Microsoft Sans Serif,10'

$Button1.Add_Click({
    [void]$type::ShowWindowAsync($handleConsole, 4);[void]$type::SetForegroundWindow($handleConsole)
    Read-Host -Prompt "Please Enter a Value"
    [void]$type::ShowWindowAsync($global:handleForm, 4);[void]$type::SetForegroundWindow($global:handleForm)
})

$Form.controls.AddRange(@($Button1))

[void]$Form.ShowDialog()

我得到:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.binary_location = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe'
driver = webdriver.Chrome(chrome_options=options, executable_path='C:/python/chromedriver.exe')
driver.get('http://google.com/')

现在,我很确定吸烟枪是:

\python\python.exe C:/py/defectURLS/app.py
C:/py/defectURLS/app.py:6: DeprecationWarning: use options instead of chrome_options
  driver = webdriver.Chrome(chrome_options=options, executable_path='C:/python/chromedriver.exe')
Traceback (most recent call last):
  File "C:/py/defectURLS/app.py", line 6, in <module>
    driver = webdriver.Chrome(chrome_options=options, executable_path='C:/python/chromedriver.exe')
  File "C:\python\lib\site-packages\selenium-3.141.0-py3.7.egg\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "C:\python\lib\site-packages\selenium-3.141.0-py3.7.egg\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\python\lib\site-packages\selenium-3.141.0-py3.7.egg\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\python\lib\site-packages\selenium-3.141.0-py3.7.egg\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\python\lib\site-packages\selenium-3.141.0-py3.7.egg\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: no chrome binary at C:/Program Files (x86)/Google/Chrome/Application/chrome.exe
  (Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT 6.1.7601 SP1 x86_64)

这向我暗示Selenium可以找到Webdriver,因为它能够报告WebDriver版本。该错误似乎表明chrome二进制文件未位于给定位置。但我完全可以肯定,这就是Chrome.exe所在的位置。我可以直接从该路径启动chrome.exe,完全没有问题。

非常感谢您提供有关可能出问题的指导。

1 个答案:

答案 0 :(得分:1)

此错误消息...

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally

...表示 ChromeDriver 无法找到Chrome二进制文件 chrome.exe

您需要考虑以下两个事实:

  • 可能您正在使用 Selenium Python Client v3.14.1 Selenium Python Client v3.141.0 ,而chrome_options现在已被弃用 。您仍然需要使用 options ,尽管 chrome_options 仍然可以使用。
  • executable_path必须受 Value 的支持,如下所示:
    • r'C:\python\chromedriver.exe'
    • "C:/python/chromedriver.exe"
    • "C:\\python\\chromedriver.exe"