问题
Bit of a Python newbie here...
Windows 7 x64 and Python 3.7
I have installed Selenium and the Chrome Webdriver. I'm using:
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/')
I'm getting:
\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)
Now, I'm pretty sure the smoking gun is:
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)
This suggests to me that Selenium can find the webdriver okay as it is able to report back the webdriver version. The error seems to suggest that the chrome binary is not being located at the given location. But I am completely certain that this IS where Chrome.exe is located. I can launch chrome.exe directly from that path with no issues at all.
Would greatly appreciate a steer on what could be wrong.
回答1:
This error message...
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
...implies that the ChromeDriver was unable to locate the chrome binary chrome.exe
You need to consider a couple of facts as follows:
- Possibly you are using Selenium Python Client v3.14.1 or Selenium Python Client v3.141.0 and
chrome_options
is deprecated now. You need to useoptions
thoughchrome_options
still works. - The Key
executable_path
must be supported with a Value as either of the following:r'C:\python\chromedriver.exe'
"C:/python/chromedriver.exe"
"C:\\python\\chromedriver.exe"
来源:https://stackoverflow.com/questions/53131669/webdriverexception-message-unknown-error-no-chrome-binary-at-c-chrome-ap